Hdu 1029 Ignatius and the Princess IV
思路:普通的cin会超时 方法很妙
1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 int main() 8 { 9 std::ios::sync_with_stdio(false); 10 int n; 11 while(cin>>n){ 12 int x,num,t=0; 13 for(int i=0;i<n;i++){ 14 cin>>x; 15 if(t==0){ 16 t=1; 17 num=x; 18 } 19 else{ 20 if(x==num) t++; 21 else t--; 22 } 23 } 24 cout<<num<<endl; 25 } 26 return 0; 27 }