国庆练习3
Posted wkfvawl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了国庆练习3相关的知识,希望对你有一定的参考价值。
Benches CF 1042A
There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of nn available.
Let kk be the maximum number of people sitting on one bench after additional mmpeople came to the park. Calculate the minimum possible kk and the maximum possible kk.
Nobody leaves the taken seat during the whole process.
Input
The first line contains a single integer n(1≤n≤100) — the number of benches in the park.
The second line contains a single integer m (1≤m≤10000) — the number of people additionally coming to the park.
Each of the next nn lines contains a single integer ai (1≤ai≤100) — the initial number of people on the ii-th bench.
Output
Print the minimum possible kk and the maximum possible kk, where kk is the maximum number of people sitting on one bench after additional mm people came to the park.
Examples
4
6
1
1
1
1
3 7
1
10
5
15 15
3
6
1
6
5
6 12
3
7
1
6
5
7 13
Note
In the first example, each of four benches is occupied by a single person. The minimum k is 3. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum k is 7. That requires all six new people to occupy the same bench.
The second example has its minimum k equal to 15 and maximum kk equal to 15, as there is just a single bench in the park and all 10 people will occupy it.
题目意思:
有n个长椅,依次给出每张椅子上最初有的人数,现在增加m个人,这m个人可以随意选择座位,k代表是所有长椅中最大的人数,最后求k的最大值与最小值。
解题思路:
k(max) = 所有的m个人坐在起初人最多的地方。
k(min) = 既保证坐的人数量最大,又要求此时的k最小,那么只能是平均分。但平均分完人数之后,很有可能均分的人数是要比你起初最大的人数要小,所以需要比较一下。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define ll long long int 5 using namespace std; 6 int a[110]; 7 int main() 8 { 9 int n,m,i,j,sum,maxs,x,y; 10 scanf("%d%d",&n,&m); 11 sum=0; 12 maxs=0; 13 for(i=0;i<n;i++) 14 { 15 scanf("%d",&a[i]); 16 sum+=a[i]; 17 if(a[i]>maxs) 18 { 19 maxs=a[i]; 20 } 21 } 22 y=maxs+m; 23 sum+=m; 24 if(sum%n) 25 { 26 x=sum/n+1; 27 } 28 else 29 { 30 x=sum/n; 31 } 32 x=max(x,maxs); 33 printf("%d %d ",x,y); 34 return 0; 35 }
Relatively Prime Pairs CF 1051B
You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105and (r−l) is always odd.
You want to split these numbers into exactly r−l+12 pairs in such a way that for each pair (i,j) the greatest common divisor of ii and jj is equal to 11. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers ll and rr (1≤l<r≤1018, r−l+1≤3⋅105, (r−l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next r−l+12lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1) numbers should be pairwise distinct and should have values from ll to rr inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
1 8
YES
2 7
4 1
3 8
6 5
题目意思:给定两个数l,r,已知l-r是奇数,那么l,r一个为奇数,一个为偶数.求[l,r]区间两两成对的数,需要满足GCD(a,b)=1;共有(l-r+1)/2对。如果满足题意
的话,输出YES,并且把每一对按要求输出。
解题思路:算是一个性质吧,相邻两个数的GCD必为1。一奇一偶。注意数据范围,开long long。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define ll long long int 5 using namespace std; 6 int main() 7 { 8 ll l,r,i; 9 scanf("%lld%lld",&l,&r); 10 printf("YES "); 11 for(i=l;i<=r;i+=2) 12 { 13 printf("%lld %lld ",i,i+1); 14 } 15 return 0; 16 }
以上是关于国庆练习3的主要内容,如果未能解决你的问题,请参考以下文章
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段