1. 程式人生 > 實用技巧 >《百度之星初賽三 * 補》

《百度之星初賽三 * 補》

Intersection

思路:可以發現,如果出現了重複的情況,那麼就會導致時間變化。

那麼,當出現了重複情況時,我們就讓左邊的往上走到上面那層,這樣對於第一個的時間,沒有變化。

因為停在原地的話,和往上走一次都+1.所以時間一樣。

但是向上走之後,對於下面的都可以向上1步,所以當發現碰撞時,都保持向上走,那麼對於碰撞的這個,它的時間到達+1。

這裡清理一個誤區,可以發現左右是一直保持著不斷運動的,因為碰撞時左邊向上走,右邊也會向右走,所以不存在改變相對位置的情況。

所以可以直接統計重複即可。

Code:

#include<bits/stdc++.h>
using namespace
std; typedef long long LL; typedef long double ld; typedef pair<int,int> pii; const int N = 20; const int M = 1e3+5; const LL Mod = 2505; #define pi acos(-1) #define INF 1e8 #define INM INT_MIN #define dbg(ax) cout << "now this num is " << ax << endl; inline int read() { int
x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();} while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();} return x*f; } unordered_map<int,int> mp1,mp2; vector<int> G[3]; int main() { int
ca;ca = read(); while(ca--) { int n;n = read(); G[1].clear(),G[2].clear(); mp1.clear(),mp2.clear(); for(int i = 1;i <= n;++i) { int id,x; id = read(),x = read(); int tim = x + (id == 1 ? 1 : 2); G[id].push_back(tim); if(id == 1) mp1[tim]++; else mp2[tim]++; } int ans = -1; for(auto v : G[1]) ans = max(ans,v+mp2[v]); for(auto v : G[2]) ans = max(ans,v+mp1[v]); printf("%d\n",ans); } system("pause"); return 0; }
View Code