注意一下数据类型为浮点型就好了
#include
#include
#include
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
偶数求和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
#include
#include
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
C - 三角形
水题,注意一下数据范围是实数
#include
#include
#include
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;
}
D - Text Volume
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.
#include
#include
#include
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='A'&&s[i]<='Z') v++;
}
ans=max(ans,v);
printf("%d\n",ans);
return 0;
}
E - Digit Sums
Time limit : 2sec / Memory limit : 1024MB
Score : 200 points
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.
Input is given from Standard Input in the following format:
N
If S(N) divides N, print Yes
; if it does not, print No
.
12
Yes
In this input, N=12. As S(12)=1+2=3, S(N) divides N.
101
No
As S(101)=1+0+1=2, S(N) does not divide N.
999999999
Yes
根据题意直接做就行了
#include
#include
#include
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;
}
F - Generous Kefa
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
#include
#include
#include
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;im) printf("NO\n");
else printf("YES\n");
}
return 0;
}
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
#include
#include
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
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
#include
#include
#include
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