#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<double>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<double, double>
#define vpii vector<pair<double, double>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace std;
pii line(pii a, pii b){
return {(b.second - a.second) / (b.first - a.first), a.second - a.first * ((b.second - a.second) / (b.first - a.first))};
}
pii intersect(pii a, pii b){
int x = (b.second - a.second)/(a.first - b.first);
return {x, a.first * x + a.second};
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin(".in");
//ofstream cout(".out");
int n,m;
cin>>n>>m;
vpii tribe[m+1];
f0r(i, n){
double a,b;
int c;
cin>>a>>b>>c;
tribe[c].pb({a,b});
}
double x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
pii mainline = line({x1,y1}, {x2,y2});
int ub = max(y1, y2);
int lb = min(y1, y2);
int q;
cin>>q;
while(q--){
int a,b;
cin>>a>>b;
int ans = 0;
f0r(i, tribe[a].size()){
f0r(j, tribe[b].size()){
pii attacker = tribe[a][i];
pii victim = tribe[b][j];
pii l = line(attacker, victim);
//cout<<l.first<<' '<<l.second<<' '<<mainline.first<<' '<<mainline.second<<'\n';
pii kousaten = intersect(l, mainline);
//cout<<kousaten.first<<' '<<kousaten.second<<'\n';
bool ok = 1;
if(attacker.second > victim.second && kousaten.second > attacker.second){
ok = 0;
}
if(attacker.second < victim.second && kousaten.second < attacker.second){
ok = 0;
}
if(attacker.second == victim.second && (kousaten.first > max(attacker.first, victim.first)|| kousaten.first < min(attacker.first, victim.first)))ok = 0;
if(kousaten.second > ub || kousaten.second < lb)ok = 0;
if(ok)ans++;
}
}
cout<<ans<<'\n';
}
}
Compilation message
dragon2.cpp: In function 'int main()':
dragon2.cpp:16:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | #define f0r(i,n) for(int i=0;i<n;i++)
......
54 | f0r(i, tribe[a].size()){
| ~~~~~~~~~~~~~~~~~~
dragon2.cpp:54:3: note: in expansion of macro 'f0r'
54 | f0r(i, tribe[a].size()){
| ^~~
dragon2.cpp:16:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | #define f0r(i,n) for(int i=0;i<n;i++)
......
55 | f0r(j, tribe[b].size()){
| ~~~~~~~~~~~~~~~~~~
dragon2.cpp:55:4: note: in expansion of macro 'f0r'
55 | f0r(j, tribe[b].size()){
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
348 KB |
Output is correct |
2 |
Correct |
74 ms |
348 KB |
Output is correct |
3 |
Correct |
87 ms |
544 KB |
Output is correct |
4 |
Correct |
34 ms |
604 KB |
Output is correct |
5 |
Correct |
19 ms |
660 KB |
Output is correct |
6 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3812 ms |
1052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
348 KB |
Output is correct |
2 |
Correct |
74 ms |
348 KB |
Output is correct |
3 |
Correct |
87 ms |
544 KB |
Output is correct |
4 |
Correct |
34 ms |
604 KB |
Output is correct |
5 |
Correct |
19 ms |
660 KB |
Output is correct |
6 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |