SPOJ BIPCSMR16 想法
来源:互联网 发布:查看ip端口是否打开 编辑:程序博客网 时间:2024/06/03 23:42
Team Building
To make competitive programmers of BUBT, authority decide to take regular programming contest. To make this contest more competitive and fruitful there are some rules given to balance a team:
1. Only 1st , 2nd and 3rd year student can participate.
2. A team must have three members.
3. All the member cannot be from same year.
You need to find out the maximum number of teams can build up according to given rules.
Input
The first line of input contain an integer T (1<=T<=10000) test case. Next T line contains three positive integer X, Y and Z (1<=X, Y, Z<=2*10^9) separated by a space which denotes the number of participants from 1st, 2nd, and 3rd year student.
Output
You need to find out the maximum number of teams can build up according to given rules.
Example
Input
2
1 2 3
1 12 3
Output
2
4
题意:一年级有X个学生,二年级有Y个学生,三年级有Z个学生,组成一支队伍的规则如下
.只有一年级,二年级,三年级的学生能够参加
.一支队伍必须有3个人
.队伍的成员不能都来自同一个年级
求最多能够组成多少支队伍
题解:不妨设x<=y<=z:
1) 2*(x+y)<=z
这个时候能组成x+y支队伍。(两个z带一个x,两个z带一个y)
2) 2*(x+y)>z
我们来搞事情:把一年级和二年级合并成一个年级。[加强条件]
设有2个三年级学生的队伍数目为a,有1个三年级学生的队伍数目为b。
a + 2b = (x+y)
2a + b = z
解得:
a+b = (x+y+z)/3
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<deque>#include<map>using namespace std;typedef long long ll;ll a[3];int main(){ int t; scanf("%d",&t); while(t--){ scanf("%lld%lld%lld",a,a+1,a+2); sort(a,a+3); if(2*(a[0]+a[1])<=a[2])printf("%lld\n",a[0]+a[1]); else printf("%lld\n",(a[0]+a[1]+a[2])/3); } return 0; }
- SPOJ BIPCSMR16 想法
- SPOJ 28270 BIPCSMR16
- SPOJ : Interesting Subset 想法题
- SPOJ - PUTNIK(想法+dp,好题)
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- SPOJ
- pip 配置python国内镜像源
- 网页分页查询实例
- 内核页表成长记
- js全局变量and局部变量的例子
- error LNK2019: 无法解析的外部符号
- SPOJ BIPCSMR16 想法
- CentOS安装Nginx
- linux学习笔记(五)
- Majority Element
- Linux下c开发 之 线程通信与pthread_cond_wait()的使用
- Oracle学习之:表连接三种方式
- cf#403 A B C
- Java和JavaScript的相互调用
- Call to undefined function pg_connect()