NC229243. The Legend of God Flukehn in Eastern
描述
输入描述
First line contains one integer, denoting the number of test cases.
For every test case, the first line contains one integeras the number of Pawns you initially own.
In the followinglines, the
line contains two integers
as the coordinates of the
Pawn. It is guaranteed that no two Pawns are on the same point and no Pawn is at
initially.
The sum offor all test cases does not exceed
.
输出描述
For every test case, output one line containing one integer as the number of Pawns defeated in a finite number of turns.
示例1
输入:
2 2 1 1 2 4 3 1 1 2 4 -1 -1
输出:
2 2
说明:
In the second example, the third Pawn can continue to move down allowing it to escape from Gold general.C++ 解法, 执行用时: 374ms, 内存消耗: 2776K, 提交时间: 2022-05-09 21:48:51
//@Author: ZIMA #include<bits/stdc++.h> using namespace std; #define IOS std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0); #define PP pair<int, int> #define endl '\n' #define ll long long #define int long long #define x first #define y second const ll INF=1e16; void solve() { int n; cin>>n; vector<PP> a(n); bool flag=false; // map<int,int> cnt; for(int i=0;i<n;i++) { cin>>a[i].x>>a[i].y; if(abs(a[i].x)>a[i].y) flag=true; // if(i>1) cnt[a[i].x]++; } if(flag) { cout<<n-1<<endl; return; } sort(a.begin(),a.end(),[&](PP t1,PP t2) { if(t1.y==t2.y) return t1.x<t2.x; return t1.y<t2.y; }); int pos=-1; set<int> st; for(int i=n-1;i>=0;i--) { if(st.find(a[i].x)==st.end()) { if((int)st.size()==2) { pos=i; break; } else if((int)st.size()==1&&abs(*st.begin()-a[i].x)>1) { pos=i; break; } st.insert(a[i].x); } } if(pos==-1) { cout<<n<<endl; return; } for(int i=0;i<n-1;i++) { auto [x1,y1]=a[i]; auto [x2,y2]=a[i+1]; if(y2-2*y1<abs(x1-x2)) { if(abs(x1-x2)>1) { cout<<n-1<<endl; return; } if(abs(x1-x2)==1&&pos>=i) { cout<<n-1<<endl; return; } } if(i+2<n) { auto [x3,y3]=a[i+2]; // cnt[a[i+2].x]--; if(y2==y3) { if(y3-2*y1<abs(x1-x3)) { if(abs(x1-x3)>1) { cout<<n-1<<endl; return; } if(abs(x1-x3)==1&&pos>=i) { cout<<n-1<<endl; return; } } } } } cout<<n<<endl; } signed main() { IOS; int __; cin>>__; while(__--) solve(); return 0; }