洛谷 2694. 接金币
原题链接
简单
作者:
我是java同学
,
2023-02-05 22:26:33
,
所有人可见
,
阅读 183
模拟 排序
- 金币会随着时间而掉落,所以想要获得金币就要优先拿到高度较低的金币,所以进行
排序
- 结论:当前横坐标与下一个横坐标之差大于纵坐标之差,则无法接到金币
- 如果用
vector
下标要从1
开始,下标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;
}
#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 <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;
}