Red packet 【模拟】
来源:互联网 发布:电脑网络修复软件 编辑:程序博客网 时间:2024/06/07 19:23
New Year is coming! Our big boss Wine93 will distribute some “Red Package”, just like Alipay and Wechat.
Wine93 has m yuan, he decides to distribute them to n people and everyone can get some money(0 yuan is not allowed and everyone’s money is an integer), Now k people has gotten money, it’s your turn to get “Red Package”, you want to know, at least how much money to give you, then you can must become the “lucky man”. and the m yuan must be used out.
Noting that if someone’s money is strictly much than others’, than he is “lucky man”.
Input
Input starts with an integer T (T <= 50) denoting the number of test case.
For each test case, three integers n, m, k (1 <= k < n <= 100000, 0< m <= 100000000) will be given.
Next line contains k integers, denoting the money that k people get. You can assume that the k integers’ summation is no more than m.
Output
Ouput the least money that you need to become the “lucky man”, if it is impossible, output “Impossible” (no quote).
Sample Input
3
3 5 2
2 1
4 10 2
2 3
4 15 2
3 5
Sample Output
Impossible
4
6
Hint
无
果然自己菜啊,就这个模拟,还wa还几次。 看来以后要多写点模拟,要多锻炼一下 严谨的思考方式。
代码
#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#define LL long longusing namespace std;const int MAXN = 500+10;const int MAXM = 3000000;/*------------------------------*/int main(){ int t;cin>>t; while(t--){ int n,m,k; scanf("%d%d%d",&n,&m,&k); int max_sum=0; int sum=0; for(int i=0;i<k;i++){ int a;scanf("%d",&a); sum+=a; max_sum=max_sum>a?max_sum:a; } m=m-sum; n=n-k; if(m<=n) puts("Impossible"); else { m=m-n; // 剩下的每个人首先得到一个 if(m&1){ int val=(m-1)/2+1+1;//剩下的人中最多得到这么多 if(val>=max_sum+1) printf("%d\n",val); else { m=m+1-max_sum-1; if(m<0) puts("Impossible"); else printf("%d\n",max_sum+1); } }else { int val=m/2+1+1; if(val>=max_sum+1) printf("%d\n",val); else { m=m+1-max_sum-1; if(m<0) puts("Impossible"); else printf("%d\n",max_sum+1); } } } } return 0;}
- Red packet 【模拟】
- Red packet
- Red packet
- [1651] Red packet【二分】
- 水题 nbut1651 Red packet
- NbUT 1651Red packet
- Red packet 二分
- 【NBUT】[1651]Red packet
- Noj 1651 Red packet
- I - Red packet
- Red packet【二分】
- Red packet~二分
- Red packet (二分)
- NBUT 1651 Red packet
- 【NBUTOJ】Red packet
- Red packet 二分算法
- Red packet NBUT
- Noj Red packet 1651 (二分)
- 解決thinkPHP出現no input file specified.問題
- 使用ReentrantLock实现生产者消费者模式
- File类 和 io流
- 一个java程序员的真实经历
- Linux中chown和chmod的区别和用法
- Red packet 【模拟】
- Java面试题全集(上)
- lintcode--删除排序数组中的重复数字 II
- [004]一步一步学懂spring
- 数据库系统概念 读书笔记(五)
- 虚拟币开发专题(以太坊:去中心化应用开发教程)
- 对javabean的一些理解
- 开源许可证的选择
- 计算机程序的思维逻辑 (8)