2017 CCPC 秦皇岛 & ZOJ 3993 - Safest Buildings (概率+规律)
2017-12-19 23:29
393 查看
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 e
4000
ntirely 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.
这题只要找规律就行。
在这个大圆里面,最外圈的概率逐渐减小,往里的一个圆环概率相等,最里的小圆概率为1.(如果存在)至于每个的范围是多少可以自己推到(猜测)
按照要求输出。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn = 100+10;
struct node
{
int s;
int flag;
} a[maxn];
int dis(int x,int y)
{
return x*x+y*y;
}
bool cmd(node a,node b)
{
if(a.s!=b.s)
return a.s<b.s;
return a.flag<b.flag;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,R,r;
scanf("%d %d %d",&n,&R,&r);
for(int i=1; i<=n; i++)
{
int x,y;
scanf("%d %d",&x,&y);
a[i].flag=i;
a[i].s=dis(x,y);
}
sort(a+1,a+1+n,cmd);
int cnt=0;
int ans[maxn];
if(R-2*r<=0)
{
int d=2*r-R;
for(int i=1; i<=n; i++)
{
if(a[i].s<=d*d)
{
cnt++;
ans[cnt]=a[i].flag;
}
}
}
if(cnt!=0)
{
printf("%d\n",cnt);
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
continue;
}
for(int i=1;i<=n;i++){
if(a[i].s<=(R-2*r)*(R-2*r)){
ans[++cnt]=a[i].flag;
}else{
break;
}
}
if(cnt!=0){
printf("%d\n",cnt);
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
continue;
}
int now=a[1].s;
cnt++;
for(int i=2; i<=n; i++)
{
if(a[i].s==now)
{
cnt++;
}
else
{
break;
}
}
printf("%d\n",cnt);
for(int i=1; i<=cnt; i++)
{
ans[i]=a[i].flag;
}
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
}
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 e
4000
ntirely 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
这题只要找规律就行。
在这个大圆里面,最外圈的概率逐渐减小,往里的一个圆环概率相等,最里的小圆概率为1.(如果存在)至于每个的范围是多少可以自己推到(猜测)
按照要求输出。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn = 100+10;
struct node
{
int s;
int flag;
} a[maxn];
int dis(int x,int y)
{
return x*x+y*y;
}
bool cmd(node a,node b)
{
if(a.s!=b.s)
return a.s<b.s;
return a.flag<b.flag;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,R,r;
scanf("%d %d %d",&n,&R,&r);
for(int i=1; i<=n; i++)
{
int x,y;
scanf("%d %d",&x,&y);
a[i].flag=i;
a[i].s=dis(x,y);
}
sort(a+1,a+1+n,cmd);
int cnt=0;
int ans[maxn];
if(R-2*r<=0)
{
int d=2*r-R;
for(int i=1; i<=n; i++)
{
if(a[i].s<=d*d)
{
cnt++;
ans[cnt]=a[i].flag;
}
}
}
if(cnt!=0)
{
printf("%d\n",cnt);
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
continue;
}
for(int i=1;i<=n;i++){
if(a[i].s<=(R-2*r)*(R-2*r)){
ans[++cnt]=a[i].flag;
}else{
break;
}
}
if(cnt!=0){
printf("%d\n",cnt);
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
continue;
}
int now=a[1].s;
cnt++;
for(int i=2; i<=n; i++)
{
if(a[i].s==now)
{
cnt++;
}
else
{
break;
}
}
printf("%d\n",cnt);
for(int i=1; i<=cnt; i++)
{
ans[i]=a[i].flag;
}
sort(ans+1,ans+1+cnt);
for(int i=1; i<=cnt; i++)
{
printf("%d%c",ans[i],i==cnt?'\n':' ');
}
}
return 0;
}
相关文章推荐
- 2017 CCPC 秦皇岛 & ZOJ 3981 - Balloon Robot 规律
- 2017 CCPC 秦皇岛 M - Safest Buildings 【几何&概率】
- 2017 CCPC 秦皇岛 & ZOJ 3983 - Crusaders Quest
- 2017 CCPC 秦皇岛 & ZOJ 3985 - String of CCPC (子串)
- 2017 CCPC 秦皇岛站 M题题解 ZOJ 3993 Safest Buildings
- 2017 CCPC 秦皇岛 & ZOJ 3987 - Numbers (贪心+大数)
- 2017 CCPC 秦皇岛 E - String of CCPC【规律】
- zoj&CCPC秦皇岛站E-思维-String of CCPC
- ZOJ 3985 String of CCPC 2017秦皇岛CCPC(子串个数)
- ZOJ 3993 && 2017CCPC秦皇岛 M:Safest Buildings
- ZOJ 3985 && 2017CCPC秦皇岛 E:String of CCPC
- hdu6237-2017哈尔滨CCPC-质因子&贪心&暴力-A Simple Stone Game
- 2017 CCPC 秦皇岛
- ZOJ 3987 && 2017CCPC秦皇岛 G:Numbers(高精度+贪心)
- 2017 CCPC 秦皇岛 L - One-Dimensional Maze 【water】
- ZOJ 3981 && 2017CCPC秦皇岛 A:Balloon Robot
- 2017 CCPC-WFinal&&HDOJ 6030 Happy Necklace(矩阵快速幂)
- 2017 CCPC 秦皇岛
- 2017秦皇岛 - ICPC - E - String of CCPC 【string的一些简单运用,思维】
- ZOJ - 3985 String of CCPC (2017CCPC秦皇岛站 简单题)