P2694 接金币
https://www.luogu.com.cn/problem/P2694
涉及知识点:模拟,结构体
橙色题
涉及知识点:模拟,结构体
橙色题
思路:
一.先输入t组数据,这组数据的n个金币,每个金币的坐标
二.对这组数据的n个金币的坐标y(由下至上) 从小到大进行排序(结构体)
三.先算出是否能接住第一个金币,((如果左右移动的时间>下降的时间则不可以接到) (a[i].x>a[i].y)
四.若可以接住第一个金币,则继续判断能否接住接下来的金币
代码:
//输入t组数据,坐标 // 对y坐标从小往大排序 //判断第一个金币是否可以接到 (如果左右移动的时间<=下降的时间则可以接到 //再判断从第二到第n个金币是否可以接到 #include<bits/stdc++.h> using namespace std; struct node{ int x,y; }a[55]; int t,n; bool cmp(node a,node b) { return a.y<b.y; } int main() { cin>>t; while(t--) { cin>>n; bool flag=0; for(int i=1;i<=n;i++) { cin>>a[i].x>>a[i].y; } sort(a+1,a+n+1,cmp); if(abs(a[1].x)>a[1].y) { printf("Notabletocatch\n"); continue; //不要写成break; } for(int i=2; i<=n; i++) { if(abs(a[i].x-a[i-1].x)>a[i].y-a[i-1].y) { printf("Notabletocatch\n"); //输出不要写错 flag=1; break; } } if(!flag) printf("Abletocatch\n"); } return 0; }