QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693565 | #5426. Drain the Water Tank | Yuanyin26 | WA | 0ms | 3844kb | C++20 | 2.2kb | 2024-10-31 16:23:29 | 2024-10-31 16:23:39 |
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)
{
double k1;
double k2;
if ((arr[l].x - arr[i].x) == 0)k1 = 1;
else k1 = (double)(arr[l].y - arr[i].y) / (arr[l].x - arr[i].x);
if ((arr[r].x - arr[i].x) == 0)k2 = 1;
else k2 = (double)(arr[r].y - arr[i].y) / (arr[r].x - arr[i].x);
if (arr[l].x <= arr[i].x && arr[i].x <= arr[r].x)cnt++;
else if (k1 > k2)cnt++;
}
else
{
double k1;
double k2;
if ((arr[l].x - arr[i].x) == 0)k1 = 1;
else k1 = (double)(arr[l].y - arr[i].y) / (arr[l].x - arr[i].x);
if ((arr[r].x - arr[i].x) == 0)k2 = 1;
else k2 = (double)(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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: 3832kb
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: 3608kb
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: 0
Accepted
time: 0ms
memory: 3540kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
8 0 0 1 0 3 -1 3 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5 0 0 170 0 140 30 60 30 0 70
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 0 0 170 0 140 30 60 30 0 100
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
5 0 0 1 2 1 5 0 2 0 1
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
3 0 0 100 0 0 100
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
input:
3 200 0 100 100 0 0
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'