Perfect Team

传送门

You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.

So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.

You are a coach at a very large university and you know that cc of your students are coders, mm are mathematicians and xx have no specialization.

What is the maximum number of full perfect teams you can distribute them into?

Note that some students can be left without a team and each student can be a part of no more than one team.

You are also asked to answer qq independent queries.

Input

The first line contains a single integer qq (1≤q≤1041≤q≤104) — the number of queries.

Each of the next qq lines contains three integers cc, mm and xx (0≤c,m,x≤1080≤c,m,x≤108) — the number of coders, mathematicians and students without any specialization in the university, respectively.

Note that the no student is both coder and mathematician at the same time.

Output

Print qq integers — the ii-th of them should be the answer to the ii query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

Example

Input

6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1

Output

1
3
0
0
1
3

 

Note

In the first example here are how teams are formed:

  1. the only team of 1 coder, 1 mathematician and 1 without specialization;
  2. all three teams consist of 1 coder and 2 mathematicians;
  3. no teams can be formed;
  4. no teams can be formed;
  5. one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team.
  6. one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.

题解:

人家说这道题是二分,但是我比较懒,从网上看了个小规律就不用二分了。

假设三类数数目分别为x,y,z。int a=min(x,y),int b=x+y+z-a*3,则如果b>=0,队伍最大数显然就是a了。如果b<0,则最大队伍数小于a,最大队伍数为(x+y+z)/3。

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>

using namespace std;

const int inf=0x3f3f3f;

int main()
{
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int t;cin>>t;
	while(t--)
	{
		int x,y,z;cin>>x>>y>>z;
		int a=min(x,y);
		int b=x+y+z-3*a;
		if(b>=0) cout<<a<<endl;
		else 
		{
			cout<<(x+y+z)/3<<endl;
		}
	}
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面代码转化为c++代码 import java.util.*; public class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in); while (scan.hasNextLine()) { String company = scan.nextLine().trim(); String team = scan.nextLine().trim(); String result = scan.nextLine().trim(); String[] results = result.split(","); System.out.println(getResult(company,team,results)); } } private static String getResult(String company, String team, String[] results) { if(!results[0].equalsIgnoreCase(company) || !results[2].equalsIgnoreCase(team)){ return "Not Found"; } return parseScore(company, team, results[1]); } private static String parseScore(String company, String team, String result) { String[] resultItems = result.split("_"); String people = resultItems[0]; String score = resultItems[1]; String evaluate = resultItems[2]; StringBuilder sb = new StringBuilder(); sb.append(company.toUpperCase()) .append(",").append(people) .append("_").append(score) .append("_").append(convertResult(score,evaluate)) .append(",").append(team); return sb.toString(); } private static String convertResult(String score, String evaluate){ String replace = Integer.parseInt(score.trim()) >= 80 || isTop3(evaluate) ? "perfect" : "better"; int index1 = evaluate.indexOf("{"); int index2 = evaluate.indexOf("}"); return evaluate.substring(0,index1) + replace + evaluate.substring(index2 + 1); } private static boolean isTop3(String evaluate){ String sort = ""; char[] evaluates = evaluate.toCharArray(); for (int i =0; i < evaluates.length; i++){ char temp = evaluates[i]; if(!Character.isDigit(temp)){ break; } sort += Character.toString(temp); } return Integer.parseInt(sort) <= 3; } }
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值