ICPC 国内予選2007C ケーキカット AOJ1149
いわれたとおりにやるだけ。特に難しいことはない。
最後priority_queueを使えば楽に答えを求められる。(まあソートでもいいけど)
#include <bits/stdc++.h> #include <map> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; const ll MOD=1e9+7; const ll INF=1e18; int dx[]={1, -1, 0, 0}; int dy[]={0, 0, 1, -1}; int cake[110][4]; priority_queue<int, vector<int> , greater<int> >que; int main(){ int n,w,d; while(true){ cin >> n >> w >> d; if(n + w + d == 0)break; cake[1][0] = 0; cake[1][1] = 0; cake[1][2] = w; cake[1][3] = d; for(int t = 1;t <= n;t++){ int p,s; cin >> p >> s; int x1 = cake[p][0],y1 = cake[p][1],x2 = cake[p][2],y2 = cake[p][3]; int count = 0; for(int i = 1;i <= t;i++){ if(i == p)continue; count++; for(int j = 0;j < 4;j++){ cake[count][j] = cake[i][j]; } } int x = x2 - x1,y = y2 - y1; s = s % ( 2*x + 2*y ); int x1_2,y1_2,x2_2,y2_2,tate = 0,len = 0; if(s < x){ len = s; }else if(s < x+y){ len = s - x; tate = 1; }else if(s < x+y+x){ len = x+y+x - s; }else{ len = x+y+x+y - s; tate = 1; } if(tate == 1){ if(len < (y+1)/2){ x2_2 = x2, y2_2 = y2, x1_2 = x1, y1_2 = y1+len; y2 = y1+len; }else{ x1_2 = x1, y1_2 = y1, x2_2 = x2, y2_2 = y1+len; y1 = y1+len; } }else{ if(len < (x+1)/2){ x1_2 = x1+len, y1_2 = y1, x2_2 = x2, y2_2 = y2; x2 = x1+len; }else{ x1_2 = x1, y1_2 = y1, y2_2 = y2, x2_2 = x1+len; x1 = x1+len; } } count++; cake[count][0] = x1,cake[count][1] = y1,cake[count][2] = x2,cake[count][3] = y2; count++; cake[count][0] = x1_2,cake[count][1] = y1_2,cake[count][2] = x2_2,cake[count][3] = y2_2; } for(int i = 1;i <= n+1;i++){ que.push( (cake[i][2]-cake[i][0])*(cake[i][3]-cake[i][1]) ); } int ans = que.top(); que.pop(); cout << ans ; while(!que.empty()){ ans = que.top(); que.pop(); cout << " " << ans; } cout << endl; } }