ZOJ - 3993 Safest Buildings (2017CCPC秦皇岛站 简单题)
2017-11-07 18:57
369 查看
Safest Buildings
Time Limit: 1 Second Memory Limit: 65536 KB
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding
getting killed themselves. BaoBao is a big fan of the game, but this time he is having some trouble selecting the safest building.
There are buildings
scattering on the island in the game, and we consider these buildings as points on a two-dimensional plane. At the beginning of each round, a circular safe area whose center is located at (0, 0) with radius will
be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius ().
The whole new safe area is entirely contained in the original safe area (may be tangent to the original safe area), and the center of the new safe area is uniformly chosen within the original safe area.
The buildings covered by the new safe area is called the safe buildings. Given the radius of the safe areas and the positions of the buildings, BaoBao wants to find all the buildings
with the largest probability to become safe buildings.
indicating the number of test cases. For each test case:
The first line contains three integers (), and (),
indicating the number of buildings and the radius of two safe circles.
The following lines
each contains 2 integers and (),
indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at ,
and all the buildings are inside the original circle.
It's guaranteed that the sum of over
all test cases will not exceed 5000.
The first line contains an integer ,
indicating the number of buildings with the highest probability to become safe buildings.
The second line contains integers
separated by a space in ascending order, indicating the indices of safest buildings.
Please, DO NOT output extra spaces at the end of each line.
题意:吃鸡游戏,求最大概率是安全房子的房子。
解题思路:简单题,稍作思考即可发现,越靠近中心点的房子,会有更高的概率成为安全房子。但有一个边界,那就是在(R-2r)内的房子都有相同的概率成为安全房子。所以简单的处理一下就好了。
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;
struct building{
double p;
int index;
}list[1000];
bool cmp(building a,building b){
return a.p<b.p;
}
bool cmp2(building a,building b){
return a.index<b.index;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
double R,r;
scanf("%d%lf%lf",&n,&R,&r);
vector<building> ans;
vector<building> others;
double x,y;
for(int i=1;i<=n;i++){
scanf("%lf%lf",&x,&y);
list[i].index=i;
if(x*x+y*y<=(R-2*r)*(R-2*r)){
ans.push_back(list[i]);
}
else{
list[i].p=x*x+y*y;
others.push_back(list[i]);
}
}
if(ans.empty()){
sort(others.begin(),others.end(),cmp);
double last=others[0].p;
for(int i=0;i<others.size();i++){
if(others[i].p==last)
ans.push_back(others[i]);
}
sort(ans.begin(),ans.end(),cmp2);
printf("%d\n",ans.size());
for(int i=0;i<ans.size()-1;i++)
printf("%d ",ans[i].index);
printf("%d\n",ans[ans.size()-1].index);
}
else{
printf("%d\n",ans.size());
for(int i=0;i<ans.size()-1;i++)
printf("%d ",ans[i].index);
printf("%d\n",ans[ans.size()-1].index);
}
}
return 0;
}
Time Limit: 1 Second Memory Limit: 65536 KB
PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding
getting killed themselves. BaoBao is a big fan of the game, but this time he is having some trouble selecting the safest building.
There are buildings
scattering on the island in the game, and we consider these buildings as points on a two-dimensional plane. At the beginning of each round, a circular safe area whose center is located at (0, 0) with radius will
be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius ().
The whole new safe area is entirely contained in the original safe area (may be tangent to the original safe area), and the center of the new safe area is uniformly chosen within the original safe area.
The buildings covered by the new safe area is called the safe buildings. Given the radius of the safe areas and the positions of the buildings, BaoBao wants to find all the buildings
with the largest probability to become safe buildings.
Input
There are multiple test cases. The first line of input contains an integer ,indicating the number of test cases. For each test case:
The first line contains three integers (), and (),
indicating the number of buildings and the radius of two safe circles.
The following lines
each contains 2 integers and (),
indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at ,
and all the buildings are inside the original circle.
It's guaranteed that the sum of over
all test cases will not exceed 5000.
Output
For each test case output two lines.The first line contains an integer ,
indicating the number of buildings with the highest probability to become safe buildings.
The second line contains integers
separated by a space in ascending order, indicating the indices of safest buildings.
Please, DO NOT output extra spaces at the end of each line.
Sample Input
2 3 10 5 3 4 3 5 3 6 3 10 4 -7 -6 4 5 5 4
Sample Output
1 1 2 2 3
题意:吃鸡游戏,求最大概率是安全房子的房子。
解题思路:简单题,稍作思考即可发现,越靠近中心点的房子,会有更高的概率成为安全房子。但有一个边界,那就是在(R-2r)内的房子都有相同的概率成为安全房子。所以简单的处理一下就好了。
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long int ll;
struct building{
double p;
int index;
}list[1000];
bool cmp(building a,building b){
return a.p<b.p;
}
bool cmp2(building a,building b){
return a.index<b.index;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
double R,r;
scanf("%d%lf%lf",&n,&R,&r);
vector<building> ans;
vector<building> others;
double x,y;
for(int i=1;i<=n;i++){
scanf("%lf%lf",&x,&y);
list[i].index=i;
if(x*x+y*y<=(R-2*r)*(R-2*r)){
ans.push_back(list[i]);
}
else{
list[i].p=x*x+y*y;
others.push_back(list[i]);
}
}
if(ans.empty()){
sort(others.begin(),others.end(),cmp);
double last=others[0].p;
for(int i=0;i<others.size();i++){
if(others[i].p==last)
ans.push_back(others[i]);
}
sort(ans.begin(),ans.end(),cmp2);
printf("%d\n",ans.size());
for(int i=0;i<ans.size()-1;i++)
printf("%d ",ans[i].index);
printf("%d\n",ans[ans.size()-1].index);
}
else{
printf("%d\n",ans.size());
for(int i=0;i<ans.size()-1;i++)
printf("%d ",ans[i].index);
printf("%d\n",ans[ans.size()-1].index);
}
}
return 0;
}
相关文章推荐
- ZOJ 3993(2017CCPC秦皇岛站M题)Safest Buildings
- ZOJ 3993 && 2017CCPC秦皇岛 M:Safest Buildings
- ZOJ - 3985 String of CCPC (2017CCPC秦皇岛站 简单题)
- ZOJ 3992 && 2017CCPC秦皇岛 L:One-Dimensional Maze
- ZOJ 3988 && 2017CCPC秦皇岛 H:Prime Set(二分匹配)
- 2017 CCPC 秦皇岛 & ZOJ 3993 - Safest Buildings (概率+规律)
- ZOJ-3987 Numbers 2017CCPC秦皇岛站G题 (二进制乱搞、贪心)
- ZOJ 3988 && 2017CCPC秦皇岛 H:Prime Set(二分匹配)
- ZOJ 3988 && 2017CCPC秦皇岛 H:Prime Set(二分匹配)
- 2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)
- ZOJ Crusaders Quest (2017CCPC秦皇岛赛区)
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot
- ZOJ - 3981 Balloon Robot (2017CCPC秦皇岛站A题 思维)
- 2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)
- ZOJ 3983 && 2017CCPC秦皇岛 C:Crusaders Quest
- ZOJ 3987 && 2017CCPC秦皇岛 G:Numbers(高精度+贪心)
- 2017 CCPC 秦皇岛站 M题题解 ZOJ 3993 Safest Buildings
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot
- ZOJ 3987 Numbers 2017CCPC秦皇岛站G题 大整数 二进制 贪心
- ZOJ 3985 && 2017CCPC秦皇岛 E:String of CCPC