有三种葡萄,每种分别有颗。有三个人,第一个人只吃第种葡萄,第二个人只吃第种葡萄,第三个人只吃第种葡萄。
适当安排三个人使得吃完所有的葡萄,并且且三个人中吃的最多的那个人吃得尽量少。
第一行数字,表示数据组数。接下来行,每行三个数
对于每组数据,输出一行一个数字表示三个人中吃的最多的那个人吃的数量。
2 1 2 3 1 2 6
2 3
1 12 13 11
12
T = int(input()) for _ in range(T): x,y,z = map(int,input().split()) food = [x,y,z] max_v,sum_v = max(food),sum(food) ans = 0 if sum_v-max_v>=max_v//2: ans =(sum_v+2)//3 else: ans = (max_v+1)//2 print(ans)
t=int(input()) for _ in range(t): a,b,c=map(int,input().split()) maxnum=max(a,b,c) total=a+b+c if maxnum//2>=total-maxnum: if maxnum%2==0: print(maxnum//2) else: print((maxnum+1)//2) else: if total%3==0: print(total//3) elif total%3==1: print((total+2)//3) else: print((total+1)//3)
import sys T = int(sys.stdin.readline().strip()) data = [] for i in range(T): line = list(map(int,sys.stdin.readline().strip().split())) data.append(line) res = [] for d in data: s = sum(d) m = max(d) a,b = divmod(s,3) c,d = divmod(m,2) a = a if b==0 else a+1 c = c if d==0 else c+1 res.append(max(a,c)) for i in res: print(i)
import sys T = int(sys.stdin.readline().strip()) data = [] for i in range(T): line = list(map(int,sys.stdin.readline().strip().split())) data.append(line) res = [] for d in data: s = sum(d) m = max(d) a,b = divmod(s,3) c,d = divmod(m,2) a = a if b==0 else a+1 c = c if d==0 else c+1 res.append(max(a,c)) for i in res: print(i)
#include <iostream> #include <cmath> using namespace std; void sort(long list[3]) // 手动冒泡排序 { if (list[0]<list[1]) swap(list[0],list[1]); if (list[0]<list[2]) swap(list[0],list[2]); if (list[1]<list[2]) swap(list[1],list[2]); } int main() { int n; long l[3], sum; cin >> n; for (int i = 0; i < n; i++) { cin >> l[0] >> l[1] >> l[2]; sort(l); sum = l[0] + l[1] + l[2]; cout << max((sum + 2) / 3, (l[0] + 1) / 2) << endl;//加2与加1是为上取整 } }
C, 2ms, 300KB
#include <stdio.h> void getMaxSum(unsigned long long int* a, unsigned long long int* max, unsigned long long int* sum) { *max = 0; *sum = 0; for (unsigned int i = 0; i < 3; ++i) { *sum += a[i]; if (*max < a[i]) { *max = a[i]; } } } int main() { int T; unsigned long long a[3]; scanf("%d", &T); while (T--) { while (scanf("%lld %lld %lld", &a[0], &a[1], &a[2]) != EOF) { unsigned long long M = 0, S = 0; getMaxSum(a, &M, &S); printf("%lld\n", (S + 2) / 3 > (M + 1) / 2 ? (S + 2) / 3 : (M + 1) / 2); } } return 0; }
//c# public class Program { public static void Main() { string line; while ((line = System.Console.ReadLine()) != null) { int[] nums = new int[int.Parse(line)]; for (int a = 0; a < int.Parse(line); a++) { string[] tokens = System.Console.ReadLine().Split(); nums[a] = Num(tokens); } foreach(var i in nums) { System.Console.WriteLine(i); } } } public static int Num(string[] str) { //排序 Array.Sort(str); //三堆葡萄赋值 int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); if (a + b > c) { return (a + b + c + (3 - 1)) / 3;//向上取整(m + (n-1))/n } if ((a + b) * 2 < c) { return (c + 1) / 2; } return (a + b + c + (3 - 1)) / 3; } }
C++
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int m; cin>>m; vector<vector<long>> grapes(m,vector<long>(3,0)); vector<long> sum(m,0); vector<long> res(m,0); for(int i=0; i<m; i++){ for(int j=0; j<3; j++){ cin >> grapes[i][j]; sum[i] += grapes[i][j]; } sort(grapes[i].begin(),grapes[i].end()); } for(int i=0; i<m; i++){ if(grapes[i][0] + grapes[i][1] > grapes[i][2]){ res[i] = (sum[i]+2)/3; } else if(2 * (grapes[i][0] + grapes[i][1]) < grapes[i][2]){ res[i] = (grapes[i][2] + 1)/2; } else{ res[i] = (sum[i]+2)/3; } cout<<res[i]<<endl; } }
import sys def eat(a,b,c): sum_ = a+b+c max_ = max(a,b,c) return (max_+1)//2 if max_>2*(sum_-max_) else (sum_+2)//3 n = int(sys.stdin.readline()) for i in range(n): a,b,c=map(int,sys.stdin.readline().split(' ')) print(eat(a,b,c))
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); long[] arr = new long[3]; for(int i = 0; i < count; i++){ long sum = 0; long maxEgde = 0; for(int j = 0; j < 3; j++){ if(sc.hasNextLong()){ arr[j] = sc.nextLong(); //maxEgde = Math.max(maxEgde, arr[j]); sum = sum + arr[j]; } } //terminal shouji wanbi Arrays.sort(arr); if(arr[2] < arr[0] + arr[1]){ System.out.println((sum + 2)/3); } else { if(2 *(arr[0] + arr[1]) < arr[2]){ System.out.println((arr[2] + 1) /2); } else { System.out.println((sum + 2)/3); } } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); long[] arr = new long[3]; for(int i=0; i<count; i++) { long maxEdge = 0; long sum = 0; for(int j=0; j<3; j++) { if(sc.hasNextLong()) { arr[j] = sc.nextLong(); maxEdge = Math.max(maxEdge, arr[j]); sum += arr[j]; } } //到此,terminal录入完毕,接下来开始处理计算录入数据 //开始计算 long avg = sum/3; if((sum - maxEdge) <= avg) { System.out.println((maxEdge+1)/2); } else { System.out.println((sum+2)/3);; } } } }
/** * JavaScript版本 * 考虑,尽可能平均地分配葡萄,才能让吃的多的人吃的最少。而/_\a,b,c可以组成一个三角形,当然如果c边过大,那么考虑将c分成两段。 * 取最长边设置为c * 情况一:a+b>c,那么只要找到a,b,c边的中点即可平分,但有可能不能整除,用Math.ceil()向上取整 * 情况二:a+b<=c, 若c>2*(a+b),那么只要取c的中点,否则还是可以去a,b,c三者中点,向上取整即可。 */ let input = []; const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) function solution(input){ let n = parseInt(input[0]); let res = []; for(let i=1;i<n+1;i++){ let arr = input[i].split(' ').map(x=>parseInt(x)); arr.sort((a,b)=>(a>b)?1:a<b?-1:0); let a = arr[0], b = arr[1], c = arr[2]; console.log(ave(a,b,c)); } } function ave(a,b,c){ let sum = a + b + c; if(a+b>c){ //res.push(Math.ceil(sum/3)); return Math.ceil(sum/3); } if(c>2*(a+b)){ return Math.ceil(c/2); } return Math.ceil(sum/3); } rl.on('line',line=>{ input.push(line); let n = parseInt(input[0]); if(input.length===n+1){ solution(input); } }) /***************************************************************************/ // 使用BigInt来解决Number越界问题let input = []; const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) function solution(input){ let n = parseInt(input[0]); // console.log(input); // console.log(2**53 - 1); for(let i=1;i<n+1;i++){ let arr = input[i].split(' ').map(x=>BigInt(x)); arr.sort((a,b)=>(a>b)?1:a<b?-1:0); let a = arr[0], b = arr[1], c = arr[2]; console.log(ave(a,b,c).toString()); } } function ave(a,b,c){ let sum = a + b + c; // console.log(a,b,c,a+b,a+b>c); if(a+b>c){ //res.push(Math.ceil(sum/3)); return (sum + 2n) / 3n; } if(c>2n*(a+b)){ return (c+1n)/ 2n; } return (sum+2n) / 3n; } rl.on('line',line=>{ input.push(line); let n = parseInt(input[0]); if(input.length===n+1){ solution(input); } })
t=int(input()) for _ in range(t): a,b,c=map(int,input().split()) maxnum=max(a,b,c) total=a+b+c if maxnum>2*(total//3): if maxnum%2==0: print(maxnum//2) else: print((maxnum+1)//2) else: if total%3==0: print(total//3) elif total%3==1: print((total+2)//3) else: print((total+1)//3)