标签:blog -- nts direct cstring nim one direction appears
Holedox Eating
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<cstring> 5 #include<queue> 6 #include<vector> 7 #include<algorithm> 8 using namespace std; 9 struct cmp 10 { 11 bool operator()(int x,int y) 12 { 13 return x>y; 14 } 15 }; 16 int main() 17 { 18 int t; 19 cin>>t; 20 int cas=1; 21 priority_queue<int >left; 22 priority_queue<int,vector<int>,cmp> right; 23 while(t--) 24 { 25 int sum=0; 26 int l,n; 27 cin>>l>>n; 28 while(!left.empty()) left.pop(); 29 while(!right.empty()) right.pop(); 30 string ok="right"; 31 int flag=0; 32 while(n--) 33 { 34 int x,y; 35 cin>>x; 36 if(x==0) 37 { 38 cin>>y; 39 if(y>=flag) right.push(y); 40 else left.push(y); 41 42 43 } 44 else 45 { 46 if(right.empty()&&left.empty()) 47 continue; 48 49 if(right.empty()||left.empty()) 50 { 51 52 if(!right.empty()) {sum+=right.top()-flag; 53 flag=right.top(); 54 right.pop(); 55 56 ok="right";} 57 else {sum+=flag-left.top(); 58 flag=left.top(); 59 60 left.pop();ok="left";} 61 62 63 } 64 else 65 { 66 if(right.top()-flag<flag-left.top()) 67 {sum+=right.top()-flag; 68 flag=right.top(); 69 70 right.pop();ok="right";} 71 else if(right.top()-flag>flag-left.top()) 72 {sum+=flag-left.top(); 73 flag=left.top(); 74 left.pop();ok="left";} 75 else { 76 if(ok=="right") 77 { 78 sum+=right.top()-flag; 79 flag=right.top(); 80 right.pop(); 81 82 } 83 else 84 { 85 sum+=flag-left.top(); 86 flag=left.top(); 87 left.pop(); 88 } 89 } 90 } 91 92 } 93 94 } 95 cout<<"Case "<<cas++<<": "; 96 cout<<sum<<endl; 97 98 } 99 return 0; 100 101 102 }
标签:blog -- nts direct cstring nim one direction appears
原文地址:http://www.cnblogs.com/blvt/p/7221578.html