![](https://i-blog.csdnimg.cn/blog_migrate/375c4e51fd5c29473836fc7c7855f606.png)
vector(注意vector的排序方法、用法)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef pair<int, int> PII;
const int N = 55;
int n;
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
vector<PII> a(n + 1);
a[0] = {0, 0};
for (int i = 1; i <= n; i ++ ) cin >> a[i].second >> a[i].first;
sort(a.begin(), a.end());
bool flag = true;
for (int i = 0; i < n; i ++ )
if ((abs(a[i].second - a[i + 1].second) - abs(a[i].first - a[i + 1].first)) > 0)
{
flag = false;
break;
}
if (flag) puts("Abletocatch");
else puts("Notabletocatch");
}
return 0;
}
结构体(两种写法)
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 55;
struct st
{
int x, y;
}a[N];
int n;
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i].x >> a[i].y;
a[0].x = 0, a[0].y = 0;
sort(a + 1, a + n + 1, [&](st A, st B) {
return A.y < B.y;
});
bool flag = true;
for (int i = 0; i < n; i ++ )
if (abs(a[i].x - a[i + 1].x) > abs(a[i].y - a[i + 1].y))
{
flag = false;
break;
}
if (flag) puts("Abletocatch");
else puts("Notabletocatch");
}
return 0;
}
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 55;
struct st
{
int x, y;
bool operator < (const st &w)
{
return y < w.y;
}
}a[N];
int n;
int main()
{
int T;
cin >> T;
while (T -- )
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i].x >> a[i].y;
a[0].x = 0, a[0].y = 0;
sort(a, a + n + 1);
bool flag = true;
for (int i = 0; i < n; i ++ )
if (abs(a[i].x - a[i + 1].x) > abs(a[i].y - a[i + 1].y))
{
flag = false;
break;
}
if (flag) puts("Abletocatch");
else puts("Notabletocatch");
}
return 0;
}