Description
Input
Output
Sample Input
3 DROP 100 TAKE 50 TAKE 20 3 DROP 3 DROP 5 TAKE 8 0
Sample Output
DROP 2 100 MOVE 2->1 100 TAKE 1 50 TAKE 1 20 DROP 2 3 DROP 2 5 MOVE 2->1 8 TAKE 1 8
<span style="font-size:18px;">#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <string> #include <algorithm> #include <queue> #include <stack> using namespace std; const double PI = acos(-1.0); const double e = 2.718281828459; const double eps = 1e-8; char s[10]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n; int flag = 0; while(cin>>n && n) { if(!flag) flag = 1; else printf("\n"); int sum1, sum2, m; sum1 = sum2 = 0; while(n--) { cin>>s>>m; if(s[0] == 'D') { <span><span class="comment">//遇到DROP将盘子存到2号堆,sum2+=m,同时输出 "DROP" 操作</span><span></span></span> printf("DROP 2 %d\n", m); sum2 += m; } else { if(sum1 >= m) { //如果1号堆剩下的盘子数 >= m,就直接输出 "TAKE" 操作 printf("TAKE 1 %d\n", m); sum1 -= m; } else { //如果1号堆剩下的盘子数 < m,先把1号堆的所有盘子输出 if(sum1 > 0) { printf("TAKE 1 %d\n", sum1); m -= sum1; sum1 = 0; } // 把2号堆的所有盘子移到1号堆 printf("MOVE 2->1 %d\n", sum2); sum1 = sum2; sum2 = 0; // 输出剩下的 m 值 if(m > 0) { printf("TAKE 1 %d\n", m); sum1 -= m; } } } } } return 0; } </span>
HDU4072Working at the Restaurant(模拟)
原文地址:http://blog.csdn.net/u014028317/article/details/45461293