P2694 接金币(贪心策略)
作者:互联网
P2694 接金币 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
}a[60];
bool cmp(node a,node b)
{
return a.y < b.y;//y坐标小的在前面
}
int main()
{
int g,n;
scanf("%d",&g);
while(g--)
{
memset(a,0,sizeof(a));//数组初始化
scanf("%d",&n);
for(int i = 1; i <= n; i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a + 1, a + 1 + n, cmp);
int flag = 0;
for(int i = 1; i <= n; i++)
{
if(abs(a[i].x - a[i-1].x) > a[i].y - a[i-1].y)
{
flag = 1;
cout << "Notabletocatch" << endl;
break;
}
}
if(flag == 0) cout << "Abletocatch" << endl;
}
return 0;
}
标签:node,cn,int,P2694,金币,scanf,贪心 来源: https://blog.csdn.net/EDGNB6666/article/details/122750227