男生女生配(抽屉原理)

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1470&cid=1142

View Code
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a, b, c, d, e, x, y;
 5     int ming, maxg;
 6     while(scanf("%d %d %d %d %d", &a, &b, &c, &d, &e))
 7     {
 8         if(a==0&&b==0&&c==0&&d==0&&e==0)break;
 9         if(c < 0)
10             ming = 0;
11         else
12             ming = c * b + 1;
13         maxg = d - e;
14         if(e <= 0)
15             x = y = 0;
16         else
17             x = a - maxg;
18             y = a - ming;
19         if(x > y)
20             printf("%d\n",-1);
21         else
22             printf("%d %d\n",x,y);
23     }
24     return 0;
25 }

总结: 注意细节; 讨论各种可能出现的情况

测试数据如下:

20 5 -1 1 1
20 5 -1 20 1
20 5 1 20 1
21 5 4 20 1
21 5 4 1 0
21 5 4 5 1
21 5 5 5 1
-10 5 4 5 4
10 5 4 3 1
55 4 2 10 1
10 1 11 5 1
1 1 0 0 0
1 1 -1 0 0
0 1 -1 0 0
0 0 0 0 0
/////////////////
20 20
1 20
1 14
-1
0 0
-1
-1
-1
-1
46 46
-1
0 0
0 1
0 0

posted @ 2013-01-29 22:00  yelan@yelan  阅读(198)  评论(0编辑  收藏  举报