【Codeforces 478C】Table Decorations
【链接】 我是链接,点我呀:)
【题意】
给你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的更多相关文章
- 【codeforces 765C】Table Tennis Game 2
[题目链接]:http://codeforces.com/contest/765/problem/C [题意] 枚举游戏先拿到k分的人胜; 然后两个人一个人得了a分,一个人得了b分; 问你最多可能进行 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【35.29%】【codeforces 557C】Arthur and Table
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【84.62%】【codeforces 552A】Vanya and Table
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【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 ...
- 【Codeforces 582A】 GCD Table
[题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数. G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: ...
- 【77.78%】【codeforces 625C】K-special Tables
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【codeforces 760A】Petr and a calendar
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- CDOJ 1330 柱爷与远古法阵(高斯消元)
CDOJ 1330 柱爷与远古法阵(高斯消元) 柱爷与远古法阵 Time Limit: 125/125MS (Java/Others) Memory Limit: 240000/240000K ...
- Kubernetes——自动扩展容器!假设你突然需要增加你的应用;你只需要告诉deployment一个新的 pod 副本总数即可
参考:http://kubernetes.kansea.com/docs/hellonode/ 现在你应该可以通过这个地址来访问这个service: http://EXTERNAL_IP:8080 或 ...
- bzoj 4537 最小公倍数
给定一张N个顶点M条边的无向图 每条边上带有权值 所有权值都可以分解成2^a*3^b的形式 q个询问,每次询问给定四个参数u.v.a和b,请你求出是否存在一条顶点u到v之间的路径,使得路径依次经过的边 ...
- bzoj 4003 [JLOI2015]城池攻占 —— 左偏树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4003 其实蛮简单的,首先一个城市只会被其子树中的骑士经过,启发我们 dfs 序用可并堆合并子 ...
- iOS通讯录(纯纯的干货)
一.iOS8.0 1.访问用户通讯录的两个框架 (1)AddressBookUI.framework 提供了联系人列表界面.联系人详情界面.添加联系人界面等,一般用于选择联系人 (2)AddressB ...
- Centos搭建图形界面VNC
#!/bin/sh unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS exec /etc/X11/xinit/xinitrc
- windows2003下svn的安装
Windows2003下svn平台搭建 编辑:dnawo 日期:2010-08-03 转自http://www.mzwu.com/article.asp?id=2557 字体大小: 小 中 大 ...
- Akka源码分析-Cluster-ActorSystem
前面几篇博客,我们依次介绍了local和remote的一些内容,其实再分析cluster就会简单很多,后面关于cluster的源码分析,能够省略的地方,就不再贴源码而是一句话带过了,如果有不理解的地方 ...
- Java使用Cipher类实现加密,包括DES,DES3,AES和RSA加密
一.先看一个简单加密,解密实现 1.1 加密 /** * content: 加密内容 * slatKey: 加密的盐,16位字符串 * vectorKey: 加密的向量,16位字符串 */ publi ...
- 蛤玮学计网 -- 简单的判断ip
心累 , 狗日的想了好多数据 , ......啥也不说了 我去哭一会 . #include<stdio.h> #include<string.h> #include<m ...