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

【题意】

给你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. 水晶报表的宽度调整方法(设计器、代码调整、rpt文件属性)

    水晶报表的宽度调整方法(设计器.代码调整.rpt文件属性) Posted on 2010-08-07 23:52 moss_tan_jun 阅读(1725) 评论(0) 编辑 收藏 经过个人反复研究后 ...

  2. Codeforces--631A--Interview(位运算)

     Interview Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     ...

  3. [BZOJ 1698] 荷叶池塘

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1698 [算法] 最短路 [代码] #include<bits/stdc++.h ...

  4. PCB SQL SERVER 发送邮件(异步改同步)

    采用SQL SERVER发送邮件是队列方式(异步)发送邮件,所以在我们执行发送邮件后,无法立即获取到邮件是否发送成功了,而在PCB行业实际应用中是需要立即获取发送邮件是否成功的状态来决定下一步逻辑该如 ...

  5. PCB NOSQL MongoDb MI流程指示数据存储结构

    一.MI流程指示结构 二.产品型号树结构(即盲埋孔板型号结构) 三.MI流程指示UI 小结:1.MI流程指示使用的表非常之多(30多张表),存储的数据分散到各个表中,而NOSQL 一个产品型号一条记录 ...

  6. JavaScript中相等==和严格相等===的区别

    在JavaScipt中==(相等)和===(严格相等,strick equality 也有译作“恒等”.“全等”)用于比较两个值是否相等,两个运算符允许任意类型的操作数.如果操作数相等则返回true, ...

  7. jQuery五屏轮播手风琴切换代码

    jQuery五屏轮播手风琴切换代码 在线演示本地下载

  8. mysql之数据去重并记录总数

    引用: http://blog.sina.com.cn/s/blog_6c9d65a10101bkgk.htmlhttp://www.jb51.net/article/39302.htm 1.使用di ...

  9. html——导航demo

    通过行内块.伪类对导航栏进行设置 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

  10. SQl基本操作——视图

    视图适合频繁查询的表:将一个查询结果作为虚拟表提供给开发人员.安全性高,视图只能查询不能修改,它是一张虚拟表.查询方便,逻辑清晰,但是性能低,一般情况下不如自己写sql语句. --创建视图 creat ...