NIT ACM 2014 寒假集训#1 初阶组

一共五题,五题全是CF的。真正会做的就三题,还有两题题目看不懂。其实都是水题。后面我懂了题意之后一下子就补掉了。

A题:

Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.

Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make bwent out candles into a new candle. As a result, this new candle can be used like any other new candle.

Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.

Input

The single line contains two integers, a and b(1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000).

Output

Print a single integer — the number of hours Vasily can light up the room for.

Sample Input

Input
4 2
Output
7
Input
6 3
Output
8

Hint

Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.

 

 

题意:每根蜡烛烧一小时,给你两个数A和B,A代表一开始有A根蜡烛,B代表每B根蜡烛可以换一根新蜡烛,问的是最久能点亮房间多久。

完全水题,被英文卡了20多分钟。

上代码。

#include <stdio.h>
#include <algorithm>
#include <string.h>
int main()
{
	__int64 a,b,sum,sum1;
	while(scanf("%I64d%I64d",&a,&b)!=EOF)
	{
		sum=0;
		sum1=0;
		__int64 i;
	   while(a)
	   {
		   	 a--;
			sum1++;
			sum++;
			if(sum%b==0)
				a++;
	   }
		printf("%I64d\n",sum1);
	}
	return 0;
}


 

B:

B - WA了不要怕!
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!

Your task is to write a program which calculates two things:

  1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
  2. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.

Input

The first line of the input contains n(2 ≤ n ≤ 2·105). In the next line there are n space-separated integers b1b2, ..., bn(1 ≤ bi ≤ 109).

Output

The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.

Sample Input

Input
2
1 2
Output
1 1
Input
3
1 4 5
Output
4 1
Input
5
3 1 2 3 1
Output
2 4

Hint

In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:

  1. choosing the first and the second flowers;
  2. choosing the first and the fifth flowers;
  3. choosing the fourth and the second flowers;
  4. choosing the fourth and the fifth flowers.

 

 也是水题一道,坑点是__int64 ,给你一些数字,让你找出极差,然后问找出极差有几种方法。

代码

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
	int n,i;
	while(scanf("%d",&n)!=EOF)
	{
        int a[220000];
		int sum=0;
		int sum1=0;
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		sort(a+1,a+1+n);
		int max=a[n];
		int min=a[1];
		for(i=1;i<=n;i++)
		{
			if(a[i]==min)
				sum++;
			if(a[i]==max)
				sum1++;
		}
		if(max==min)
		{
			printf("0 %I64d\n",(__int64)n*(n-1)/2);
		}
		else
			printf("%d %I64d\n",max-min,(__int64)sum*sum1);
	}
	return 0;
}


 

C:
C - 烫烫烫烫烫
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:

  • deletes all the vowels,
  • inserts a character "." before each consonant,
  • replaces all uppercase consonants with corresponding lowercase ones.

Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.

Help Petya cope with this easy task.

Input

The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.

Output

Print the resulting string. It is guaranteed that this string is not empty.

Sample Input

Input
tour
Output
.t.r
Input
Codeforces
Output
.c.d.f.r.c.s
Input
aBAcAba
Output
.b.c.b

 

一开始被吓着了,后来有人过了,发现还是水题。主要把题目列给你的A O Y E U I 全部去掉就好。还有就是所有的字母都是小写的。先转小写。然后删,然后输出。

代码

#include <stdio.h>
#include <algorithm>
#include <string.h>
int main()
{
	char a[2000];
	while(gets(a))
	{
		int i;
		int l=strlen(a);
		for(i=0;i<l;i++)
		{
			if(a[i]>='A' &&a[i]<='Z')
				a[i]+=32;  //转小写
		}
		for(i=0;i<l;i++)
		{
			if(a[i]=='a' ||a[i]=='o' ||a[i]=='y' ||a[i]=='e' ||a[i]=='u' ||a[i]=='i')
				a[i]=-1;   //  删
		}
		
		for(i=0;i<l;i++)
		{
			if(a[i]!=-1)
			{
				printf(".");
				printf("%c",a[i]); //输出
			}
		}
		printf("\n");
	}
}


 

 

D:

D - 小呀小苹果儿
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

 

Description

Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.

Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.

But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

Input

The first line contains an integer n(1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

Output

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

Sample Input

Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO

Hint

In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.

 

 

题意:买一些苹果分给两个人,问是否能够平均的分。苹果就两种,一百克的和两百克的。并且不能切。这题卡了一个小时。其实讨论几种情况就好,总重量不能被200整除的直接NO。100的个数为奇数直接NO(因为必然不能分的刚好)。如果N为一直接NO。如果200的个数为奇数并且100没有直接NO。其他都是YES。

上代码

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()  
{  
	int a[2000];
    int n,i,sum1,sum2,sum;  
    while(~scanf("%d",&n))  
    {  
        sum1=sum2=sum=0;  
        for(i=0;i<n;i++)  
        {  
            scanf("%d",&a[i]);  
            sum+=a[i];  
            if(a[i]==100)  
				sum1++;  
			if(a[i]==200)
                sum2++;  
        }  
        if(n==1)  
        {  
            printf("NO\n");  
            continue;  
        }  
        if(sum%200!=0 || sum1%2)  
            printf("NO\n");  
        else  
        {  
			if(sum2%2 && sum1==0)  
                printf("NO\n");  
			else  
				printf("YES\n");     
		}  
	}  
	
    return 0;  
}  


 

E:
E - 结构体你会了咩~
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.

According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.

Input

The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take.

Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

Output

Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.

Sample Input

Input
3
5 2
3 1
4 2
Output
2
Input
3
6 1
5 2
4 3
Output
6

Hint

In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.

In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.

 

这题真心醉,一开始就开始看这题,结果反反复复到最后愣是没把题目看懂。讲下题意。给你一个N ,代表N场考试。问你最少能在几号考完。必须先考号码在前的一科

3
6 1
5 2
4 3

6

看这个案例。输出是6号考完

6 1

代表第一科可以在6号考,也可以在一号考,

5 2

代表第二科可以再5号考,也可以在2号考。

4 3

类似

因为4号码最靠前,所以先考4,因为也可以三号考,所以三号就考完了第三科,然后再看5 2。

因为2<3,所以必然不可能第二科在2号考,所以第二科在5号考。

再上去,第一科在6号考。

所以6号考完。

要做的事情很简单。先将考号排序。

然后判断即可。上代码

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node
{
	int x,y;
}
;
bool cmp(node a,node b)
{
	if(a.x==b.x)   //如果考号是相等的
		return a.y<b.y;  //按小到大排,因为号码小的要先考
	return a.x<b.x;  //否则按考号从小到大。
}
int main()
{
	node f[6000];
	int n,i;
	while(scanf("%d",&n)!=EOF)
	{
		int sum;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&f[i].x,&f[i].y);
		}
		sort(f+1,f+1+n,cmp);
		sum=f[1].y;   
		for(i=1;i<=n;i++)
		{
			if(sum<=f[i].y)    // 如果比它小的话,则说明可以按第二种的号码考试。
				sum=f[i].y;
			else
				sum=f[i].x;  //否则只能按原来(第一种)的号码考试。
		}
		printf("%d\n",sum);  
	}
	return 0;
}


 

 

 

总结:还是要认真的读题。其实都是水题啊。加强英语阅读的能力。。做题的时候要细心,避免不必要的WA。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值