zoukankan      html  css  js  c++  java
  • 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
    ", max(cal(n, m), cal(m, n)));
    28     }
    29     return 0;
    30 }

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

  • 相关阅读:
    BeautifulSoup模块
    爬取校花网视频
    爬虫基本原理
    python学习笔记-50 使用SQLAlchemy
    python学习笔记-49 使用MySQL
    PTA天梯 L3-007 天梯地图
    VS2013 创建ASP.NET MVC 4.0 未指定的错误(异常来自HRESULT: 0x80004005(e_fail))
    动态规划--新手
    文件上传绕过
    C# → 数据库
  • 原文地址:https://www.cnblogs.com/windysai/p/4307566.html
Copyright © 2011-2022 走看看