A - 青年歌手大奖赛_评委会打分
青年歌手大奖赛_评委会打分
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104819 Accepted Submission(s): 51776
注意一下数据类型为浮点型就好了
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e3+6;
double a[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%lf",a+i);
sort(a,a+n);
double sum=0;
for(int i=1;i<n-1;i++)
sum+=a[i];
printf("%.2f\n",sum/(n-2));
}
return 0;
}
B - 偶数求和
偶数求和Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 106685 Accepted Submission(s): 44357
Problem Description
有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。
Input
输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。
Output
对于每组输入数据,输出一个平均值序列,每组输出占一行。
Sample Input
3 24 2
Sample Output
3 63 7
|
细心一点儿就好了
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+6;
int a[120];
int main()
{
for(int i=0;i<102;i++)
a[i]=i*2;
int n,m,sum;
while(~scanf("%d %d",&n,&m))
{
for(int i=0;i<n/m;i++)
{
sum=0;
for(int j=i*m+1;j<=m*(i+1);j++)
{
sum+=a[j];
}
if(i) printf(" ");
printf("%d",sum/m);
}
if(n%m)
{
sum=0;
int x=n-(n/m)*m;
for(int i=m*(n/m)+1;i<=n;i++)
sum+=a[i];
printf(" %d",sum/x);
}
printf("\n");
}
return 0;
}
三角形
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 108913 Accepted Submission(s): 35707
水题,注意一下数据范围是实数
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e3+6;
int main()
{
double a,b,c;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lf %lf %lf",&a,&b,&c);
double x=max(a,max(b,c));
if(x<(a+b+c-x)) printf("YES\n");
else printf("NO\n");
}
return 0;
}
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
7 NonZERO
5
24 this is zero answer text
0
24 Harbour Space University
1
单词的Volume代表: 这个单词中大写字母的个数
短文的Volume等于该短文包含的所有单词的Volume的最大值
你的目标是计算给定短文的Volume.
Input
第一行包含一个整数n (1 ≤ n ≤ 200) — 代表短文的长度.
第二行包含一行短文,由单个空格分开的一些单词s1, s2, ..., si组成,由大写字母和小写字母组成.
Output
输出一个整数 — 该短文的Volume.
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e3+6;
char s[maxn];
int main()
{
int n;
scanf("%d",&n);
getchar();//吸收回车符
gets(s);
int v=0;//记录单词的Volume
int ans=0;//记录短文的Volume
for(int i=0;i<n;i++)
{
if(s[i]==' ')
{
ans=max(ans,v);
v=0;
}
if(s[i]>='A'&&s[i]<='Z') v++;
}
ans=max(ans,v);
printf("%d\n",ans);
return 0;
}
Digit Sums
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
Problem Statement
Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(101)=1+0+1=2.
Given an integer N, determine if S(N) divides N.
Constraints
- 1≤N≤109
Input
Input is given from Standard Input in the following format:
N
Output
If S(N) divides N, print Yes
; if it does not, print No
.
Sample Input 1
12
Sample Output 1
Yes
In this input, N=12. As S(12)=1+2=3, S(N) divides N.
Sample Input 2
101
Sample Output 2
No
As S(101)=1+0+1=2, S(N) does not divide N.
Sample Input 3
999999999
Sample Output 3
Yes
给你一个整数 N, 判断 S(N) 能否整除 N .
Constraints
1 <= N <= 10^9
Input
输入仅一行,一个整数N
Output
如果 S(N) 能整除 N, 输出 Yes; 否则, 输出 No.
根据题意直接做就行了
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e3+6;
int s(int n)
{
int ans=0;
while(n)
{
ans+=n%10;
n/=10;
}
return ans;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n%s(n)) printf("No\n");
else printf("Yes\n");
}
return 0;
}
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
4 2 aabb
YES
6 3 aacaab
NO
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
别想太多......
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+6;
int a[100];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
memset(a,0,sizeof(a));
char s[maxn];
scanf("%s",s);
for(int i=0;i<strlen(s);i++)
a[s[i]-'A']++;
sort(a,a+100,cmp);
if(a[0]>m) printf("NO\n");
else printf("YES\n");
}
return 0;
}
G - Godsend
Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?
First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
4 1 3 2 3
First
2 2 2
Second
In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose.
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e3+6;
int main()
{
int n;
while(~scanf("%d",&n))
{
ll sum=0;
int k=0;
for(int i=0;i<n;i++)
{
int x;
scanf("%d",&x);
sum+=x;
if(x&1) k=1;
}
if(sum&1) printf("First\n");
else if(k) printf("First\n");
else printf("Second\n");
}
return 0;
}
H - Sorting Railway Cars
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train.
The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
Print a single integer — the minimum number of actions needed to sort the railway cars.
5 4 1 2 5 3
2
4 4 1 3 2
2
In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
这一题是要找最长的连续递增子序列,自己想了好久没想出来,竞赛结束后看了网上大佬们写的代码,发现原来是这样做的,
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e5+6;
typedef long long ll;
int a[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
int k;
int ans=0;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
scanf("%d",&k);
if(a[k-1])
{
a[k]=a[k-1]+1;
}
else
a[k]=1;
ans=max(ans,a[k]);
}
printf("%d\n",n-ans);
}
return 0;
}