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

【题意】

给你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. JSP-Runoob:JSP 状态码

    ylbtech-JSP-Runoob:JSP 状态码 1.返回顶部 1. SP HTTP 状态码 HTTP请求与HTTP响应的格式相近,都有着如下结构: 以状态行+CRLF(回车换行)开始 零行或多行 ...

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

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

  3. smarty用法

    smarty学习指南 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计.下载Smarty文件放到你们站点 ...

  4. Java 删除List元素的正确方式

    方式一:使用Iterator的remove()方法 public class Test { public static void main(String[] args) { List<Strin ...

  5. OI——不后悔的两年

    NOI2014,悲惨的考跪,99+170+130 399 Cu滚粗.最终签到了复旦的一本,还算是有点结果吧.(其实我一开始就想读复旦我会说?)回首这两年,就像一场梦一样,从一无所知的小白到进入省队再到 ...

  6. linux的touch命令

    linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a    ...

  7. 关于编辑器对<input>标签报错提示“表单输入没有相关label”的问题

    相信很多朋友在制作表单的时候,我们的编辑器会有下图的相关提示吧 我们发现虽然这样并不影响我们的正常使用,但是看着这样的报错提示总是很让人心烦,那么这到底是为什么呢? 其实,这是因为编辑器建议我们在使用 ...

  8. 怎么用css hack处理各浏览器兼容IE6,IE7,IE8,IE9/ FF

    第一:什么事浏览器兼容性 浏览器兼容性问题又被称为网页兼容性或网站兼容性问题,指网页在各种浏览器上的显示效果可能不一致而产生浏览器和网页间的兼容问题.在网站的设计和制作中,做好浏览器兼容,才能够让网站 ...

  9. sql server 数据分析优化实战(一)——SQL语句优化

    前言 在我们进行数据分析的时候,首要的目标是根据业务逻辑,通过编写SQL代码得到我们想要的结果,这是毋庸置疑的.一般情况下,由于我们分析的数据量比较少,体会不出SQL语句各种写法的性能优劣,对SQL代 ...

  10. 开源业务规则引擎JBoss Drools

    Drools 是什么? 规则引擎由推理引擎发展而来,是一种嵌入在应用程序中的组件,实现了将业务决策从应用程序代码中分离出来,并使用预定义的语义模块编写业务决策.接受数据输入,解释业务规则,并根据业务规 ...