codeforces 519C. A and B and Team Training 解题报告

题目链接:http://codeforces.com/contest/519/problem/C

题目意思:给出 n 个  experienced participants  和 m 个 newbies ,需要组成尽量多的组,组由3个人组成。有两种组合方式:(1)1 个 experienced participant 和 2 个  newbie  (2)2 个

 experienced participant 和 1 个  newbie。问最多能组成的组数是多少组。

  昨天做的时候不是暴力做的,惯性思维所害!以为只有两种情况:尽可能多的方式(1) 或者尽可能多的方式(2)。这样做一直过不了pretest 5!

  暴力改回就过了!

     

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 int cal(int n, int m)
 8 {
 9     int res = 0;
10     for (int i = 1; i <= n; i++) {
11         int tn = min(i, m/2);   
12         int tm = m - tn*2;
13         int t = min((n-i)/2, tm);
14         res = max(res, tn+t);
15     }
16     return res;
17 }
18 
19 int main()
20 {
21     #ifndef ONLINE_JUDGE
22         freopen("in.txt", "r", stdin);
23     #endif // ONLINE_JUDGE
24 
25     int n, m;
26     while (scanf("%d%d", &n, &m) != EOF) {
27         printf("%d\n", max(cal(n, m), cal(m, n)));
28     }
29     return 0;
30 }

      PS: 纪念第300篇博客完成[^__^] !!毕业设计完成前最后一篇博客!答辩后再见!

posted @ 2015-03-01 20:55  windysai  阅读(541)  评论(0编辑  收藏  举报