QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693396 | #5426. Drain the Water Tank | Yuanyin26 | WA | 0ms | 3612kb | C++20 | 1.8kb | 2024-10-31 16:04:42 | 2024-10-31 16:04:43 |
Judging History
answer
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<string.h>
#include <string>
#include<math.h>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<queue>
#include<stack>
#include<functional>
#include<deque>
using namespace std;
#define MAXN 301000;
#define ll long long
#define lll unsigned long long
#define PA pair<ll,ll>
#define INF (ll)0x3f3f3f3f*(ll)1000000
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
struct node {
int x, y;
};
void solve() {
int n; cin >> n;
vector<node>arr(2 * n);
bool c = false;
for (int i = 0; i < n; i++) {
cin >> arr[i].x >> arr[i].y;
arr[i + n] = arr[i];
if (arr[i + n].y != arr[i - 1 + n].y)c = true;
}
if (!c) {
cout << 0 << endl;
return;
}
vector<bool>visit(n, false);
int cnt = 0;
for (int i = n; i < 2 * n; i++) {
if (visit[i % n])continue;
int l = i - 1, r = (i + 1) % (2 * n);
while (arr[l].y == arr[i].y)l--;
while (arr[r].y == arr[i].y)r = (r + 1) % (2 * n);
int p = r - 1;
if (p < 0)p = 2 * n - 1;
while (p != l) {
visit[p % n] = true;
p--;
if (p < 0)p = 2 * n - 1;
}
if (arr[i].y < arr[l].y && arr[i].y < arr[r].y)
{
if (arr[l].x <= arr[r].x)cnt++;
else
{
double k1;
double k2;
if ((arr[l].x - arr[i].x) == 0)k1 = 1;
else k1 = (arr[l].y - arr[i].y) / (arr[l].x - arr[i].x);
if ((arr[r].x - arr[i].x) == 0)k2 = 1;
else k2 = (arr[r].y - arr[i].y) / (arr[r].x - arr[i].x);
if (k1 > k2)
{
if (arr[r].x <= arr[i].x && arr[i].x <= arr[l].x);
else cnt++;
}
}
}
}
cout << cnt << endl;
}
int main() {
IOS;
int t = 1;// cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
6 0 0 1 1 2 1 3 0 3 2 0 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
8 4 4 0 4 0 2 1 2 2 2 2 0 3 0 4 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
7 1 0 3 4 0 3 1 2 2 3 1 1 0 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3604kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'