【链接】 我是链接,点我呀:)

【题意】

给你r,g,b三种颜色的气球
每张桌子要放3个气球
但是3个气球的颜色不能全都一样
(允许两个一样,或者全都不一样)
问你最多能装饰多少张桌子

【题解】

先把每张桌子都装饰上
a,b,c三种不同颜色的气球
(显然这样的桌子最多为Math.min(r,g,b)张)
然后把气球的个数减掉
这种方法设置为ABC
然后
肯定只剩两种气球还可能有剩余
那么就用其中数量比较多的一种放2个,比较少的放1个(也是贪心,但不一定对)
这种方法定义为AAB
然后再减少A,B的数量
此后
有两种情况
①A还剩很多,B已经没了
那么我们就用剩余的A去和"ABC"方案中的B或者C替换一下(替换谁都无所谓,只要不是A就行)
这样就可能再凑出来一组"AAB"或者"AAC"
所以方案还可以加上min(restA/3,num("AAB") );
②A只剩1个或0个(因为是减去*2),B还有很多
如果A剩一个,B还有2个以上
那么可以凑出来一个"ABB",ans++,然后A=0,b-=2
然后就变成A剩0个,B还有很多的情况
这个时候我们可以用B去替换我们上面定义的"ABC"中的A或者上面定义的"AAB"中的A(①中因为是A剩余,但是A如果替换的话,就不符合题意了,但是B可以替换)
因此答案再累加对应的数量就好

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e6;
static class Task{
public void solve(InputReader in,PrintWriter out) {
int r,g,b;
int []a = new int[3];
for (int i = 0;i < 3;i++) a[i] = in.nextInt();
Arrays.sort(a, 0,3);
int ans = a[0];
int g1 = ans;
for (int i = 1;i < 3;i++) a[i]-=a[0];
int temp = Math.max(a[1], a[2]);
int temp1 = Math.min(a[1], a[2]); int g2 = Math.min(temp/2, temp1);
ans = ans + g2; temp = temp - g2*2;temp1-=g2;
if (temp1==0) {
//temp1变成0,temp可能会有剩余
int g3 = Math.min(temp/3, g1);
ans = ans + g3;
temp = temp-g3*3;
}else {
//temp没有那么多了,temp1还有剩余
if (temp!=0) {
//temp==1
temp--;
if (temp1>=2) {
ans++;
temp1-=2;
}
} //temp变成0了,temp1还可能有剩余和之前3个3个的换一下
int g3 = Math.min(temp1/3, g1);
temp1 = temp1-g3*3;
ans += g3;
int g4 = Math.min(temp1/3, g2);
temp1 = temp1-g4*3;
ans = ans + g4;
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 478C】Table Decorations的更多相关文章

  1. 【codeforces 765C】Table Tennis Game 2

    [题目链接]:http://codeforces.com/contest/765/problem/C [题意] 枚举游戏先拿到k分的人胜; 然后两个人一个人得了a分,一个人得了b分; 问你最多可能进行 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【84.62%】【codeforces 552A】Vanya and Table

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 509A】Maximum in Table

    [题目链接]:http://codeforces.com/contest/509/problem/A [题意] 给你一个递推式f[i][j] = f[i-1][j]+f[i][j-1]; 让你求f[i ...

  6. 【Codeforces 582A】 GCD Table

    [题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数.          G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: ...

  7. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. 【codeforces 760A】Petr and a calendar

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. ubuntu安装go语言

    1.下载安装包 2.解压 sudo tar -zvxf go1.10.linux-amd64.tar.gz -C /usr/local 3.配置 sudo vim /etc/profile 添加 #s ...

  2. bzoj2662 [BeiJing wc2012]冻结 ——分层图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2662 分层图: 我也不知道我写的是不是 bfs (dijkstra?). 代码如下: #in ...

  3. vue项目打包之后首页白屏的问题

    本地的vue项目在server端浏览没问题,但是执行npm run build 打包之后在本地预览是白屏. 解决方法 1.路径问题 在config文件夹中找到index.js打开把assetsPubl ...

  4. etcd磁盘清理步骤

    etcd默认的空间配额限制为2G,超出空间配额限制就会影响服务,所以需要定期清理 以下是etcd磁盘清理的步骤: 1. 显示空间配额: ETCDCTL_API=3 etcdctl --endpoint ...

  5. linux下打开windows txt文件中文乱码问题 (转载)

    转自:http://blog.csdn.net/imyang2007/article/details/7448177 在linux操作系统下,我们有时打开在windows下的txt文件,发现在wind ...

  6. Linux文件属性相关补充及软硬连接

    第1章 文件属性相关 1.1 文件的属性 1.1.1 扩展名 windows  通过扩展名区分不同的类型的文件 linux 扩展名是给人类看的 方便我们区分不同类型文件 .conf      配置文件 ...

  7. Is the Information Reliable?(差分约束系统)

    http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...

  8. HDU 3785 找寻大富翁

    2019-06-06 08:30:03 坚持!!! 做这些水题,都觉得心累,特别是HDU的题,我PE了3发

  9. python自动化测试学习笔记-6urllib模块&request模块

    python3的urllib 模块提供了获取页面的功能. urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capat ...

  10. 【Codeforces1109B_CF1109B】Sasha and One More Name(字符串)

    题目: Codeforces1109B 我打的是 Div2 ,所以我看到的题号实际上是 1113D -- 考场上傻了没敢大力猜结论没做出来这道题,不幸掉分-- 1869->1849 嘤嘤嘤 翻译 ...