第二次练习

A.Watermelon

time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys. Output Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Sample test(s) input 8 output YES Note For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
B. Taxi

time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? Input The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group. Output Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. Sample test(s) input 5 1 2 4 3 3 output 4 input 8 2 3 4 4 2 1 3 1 output 5 Note In the first test we can sort the children into four cars like this:
 the third group (consisting of four children),  the fourth group (consisting of three children),  the fifth group (consisting of three children),  the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.

C. Team

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Print a single integer — the number of problems the friends will implement on the contest.
Sample test(s) input 3 1 1 0 1 1 1 1 0 0 output 2 input 2 1 0 0 0 1 1 output 1 Note In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

D. Word Capitalization

 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. Input A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Output the given word after capitalization. Sample test(s) input ApPLe output ApPLe input konjac output Konjac

 E. Xenia and Ringroad

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house
number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time. Input The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). The second line contains m integers a1, a2, ..., am(1 ≤ ai ≤ n). Note that Xenia can have multiple consecutive tasks in one house. Output Print a single integer — the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier. Sample test(s) input 4 3 3 2 3 output 6 input 4 3 2 3 3 output 2 Note In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.

F. Caisa and Pylons

time limit per test 1 second memory limit per test 256 megabytes input standard input output
standard output Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game? Input The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons. Output Print a single number representing the minimum number of dollars paid by Caisa. Sample test(s) input 5 3 4 3 2 4 output 4 input 3 4 4 4 output 4 Note In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
G. Given Length and Sum of Digits...

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. Input The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers. Output In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). Sample test(s) input 2 15 output 69 96 input 3 0 output -1 -1

 

 

A

#include<stdio.h>  //580分
int main()
{
int w;
scanf("%d",&w);
if(w>2 && (w%2==0)) printf("YES\n");
else  printf("NO\n");
return 0;
}

B

#include<stdio.h>
int main()
{
int n,a[100002];
int count,w=0,x=0,y=0,z=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++)
{
if(a[i]==4) w++;
else if(a[i]==3) x++;
else if(a[i]==2) y++;
else  z++;
}
if(x>z)
{
 if(y%2==0)
 count=w+x+(y/2);
 else count=w+x+(y/2+1);

}
else 
{
 if((z-x)%2==0)
 count=w+x+(2*y+(z-x))/4;
 else count=w+x+(2*y+(z-x)/4+1);
}
printf("%d\n",count);
return 0;
}

 

C
#include<stdio.h>
int main()
{
int n,b[5],count,row=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
 count=0;
 for(int j=0;j<3;j++)
 {
  scanf("%d",&b[j]);
  if(b[j]==1) count++;
 }
 if(count>=2)  row++;
}
printf("%d\n",row);
return 0;
}

D

#include<stdio.h>
int main()
{
int i;
char s[1002];
gets(s);
if(s[0]>'a' && s[0]<'z') s[0]-=32;
puts(s);
putchar('\n');
return 0;
}

E


#include<stdio.h>
typedef long long LL;
int main()
{
LL i,x,y,m,n,count;
scanf("%lld%lld",&n,&m);
count=0;
y=1;
for(i=1;i<=m;i++)
{
 scanf("%lld",&x);
if(x>=y) count=count+x-y;
else  count=count+x+n-y;
y=x;
}
printf("%lld\n",count);
return 0;
}

F

#include<stdio.h>
int main()
{
int n,i,a[100002];
scanf("%d",&n);
int max=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(max<a[i])  max=a[i];  
}
printf("%d\n",max);
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值