## 【Codeforces 478C】Table Decorations

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

(允许两个一样,或者全都不一样)

【题解】

a,b,c三种不同颜色的气球
(显然这样的桌子最多为Math.min(r,g,b)张)

①A还剩很多,B已经没了

②A只剩1个或0个(因为是减去*2),B还有很多

【代码】

``````import java.io.*;
import java.util.*;

public class Main {

static PrintWriter out;

public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
out = new PrintWriter(System.out);
//code start from here
out.close();
}

static int N = (int)1e6;
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);
}
}

public StringTokenizer tokenizer;

tokenizer = null;
}

public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
}catch(IOException e) {
throw new RuntimeException(e);
}
}
}

public int nextInt() {
return Integer.parseInt(next());
}
}
}``````

0条评论