UPC 2021个人训练赛第10场

问题 A: No Problem!

时间限制: 1 Sec  内存限制: 128 MB

题目描述

Programming contests are being arranged so frequently these days. While this might be a good news for the contestants, the scenario is completely opposite for the problemsetters. So far, the problemsetters somehow managed to produce some sorts of a set & say “No problem!”. But it is doubtful how long will it be possible if the trend of arranging contests in a short notice continues.
You are given the number of problems created in every month of a year and number of problems required in each month. If N problems are required in a month & there are not enough problems at that time, all contests of that month is canceled. Write a program to determine if there are enough problems for the contests. Please keep in mind that, if a problem is created in month X, it can only be used in month X + 1 & the later months.

输入

The first line of every test case has an integer S (0 ≤ S ≤ 100). Number of problems that is ready at the beginning of the year. The 2-nd line has 12 space separated integers, denoting the number of problems created in each of the 12 months of that year. The months are in the same order as they appear in a year. The 3-rd line has another 12 space separated integers, the number of problems required to use in contests in those 12 months (With the same order as above). These integers will be between 0 & 20 (inclusive). The end of input will be denoted by a negative integer.

输出

For each test case, print a line of the form, ‘Case X:’, where X is the case number. Then print 12 lines.
If there are enough problems to meet the requirements in month i (1 ≤ i ≤ 12), print ‘No problem!
:D’ in the i-th line, otherwise print ‘No problem. :(’

样例输入

5
3 0 3 5 8 2 1 0 3 5 6 9
0 0 10 2 6 4 1 0 1 1 2 2
-1

样例输出

Case 1:
No problem! :D
No problem! :D
No problem. :(
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D
No problem! :D

 

第一行的数据为初始可用题目量,适用于所有月份;第二行的每个数据只适用于该月之后。

每次现有可用题目量now加上该月准备的题目量lis[i],now与该月需求cost[i]比较:够用就goodend,now减去cost[i],否则badend,now不变。

该月的状态只与以往月份有关,可边读入边solve。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

string YES = "No problem! :D", NO = "No problem. :(";

ll now;

int main() {
	ll cnt = 0;
	while (cin >> now && now >= 0) {
		ll lis[13];
		ll cost[13];
		_rep(i, 1, 12)	lis[i] = read();
		cout << "Case " << ++cnt << ':' << endl;
		_rep(i, 1, 12) {
			cost[i] = read();
			if (now >= cost[i]) {
				cout << YES << endl;
				now -= cost[i];
			} else cout << NO << endl;
			now += lis[i];
		}
	}
	return 0;
}

 

 

问题 E: Memory Overflow

时间限制: 1 Sec  内存限制: 128 MB

题目描述

The Great Sultan Mahbub is having some serious issues with his memory. His busy days filled with great works and surrounded by even greater people have brought him to a situation where he has become quite forgetful. For example, he often forgets trivial things like the size of his suit, his weight,small grammatical issues related to gender & number, the address of his in-laws house, how to ride a cycle, deadlines, the day of the week, the name of the guy who forgot his wedding day and even the date of his own wedding (thus spending the day writing alternate solutions to ICPC problems). But when his father-in-law captured him to his in-laws house and he failed to recognize his mother-in-law it became a fiasco. And after some rather presumable events following that debacle, the detail of which does not seem really safe to mention, he decided that the matter has become pressing enough for his attention. His physician is startled by this weird problem and decides to collect statistical data to begin with.
During the examination period consisting n consecutive days, the Sultan meets a single person everyday. He only recognizes the person if he has met him in the last k days (excluding today of course). You need to count the number of days (among these n days) he manages to recognize the people he meets. You can assume that before these n consecutive days he did not meet any person.

输入

The input begins with a number t (1 ≤ t ≤ 100), the number of test cases. Each of the following lines contains a case. A case begins with n (1 ≤ n ≤ 500) & k (1 ≤ k ≤ 500). A list of n names follows. All
names consist of a single uppercase letter and names are unique. They are given in the order of which Sultan meets them during the investigation. There won’t be any invalid character or space between
any two names.

输出

For each test case produce a line of the form ‘Case X: Y ’. X is the serial number of the test case while Y is the number of people Sultan recognizes.
Illustration of Third sample:
Day 1: Sultan remembers nobody, meets ’M’. Does not recognize.
Day 2: Remembers only ’M’ but meets ’A’. Does not recognize again.
Day 3: Now remembers ’M’ & ’A’. Meets ’H’. Recognition count remains 0.
Day 4: Forgets ’M’, remembers ’A’ & ’H’. Meets ’B’. Still nothing happens.
Day 5: Forgets ’A’, remembers ’H’ & ’B’. Meets ’U’. No luck yet.
Day 6: Forgets ’H’, remembers ’B’ & ’U’. Meets ’B’ again and recognizes this time making the recognition count 1.

样例输入

3
6 2 SULTAN
6 1 MAHBUB
6 2 MAHBUB

样例输出

Case 1: 0
Case 2: 0
Case 3: 1

 

一开始创了一个队列,模拟记忆的人,但不过,改为记录当前人员的记忆程度:mp[name]。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#include<limits.h>
#include<float.h>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
#define _re_for(i, a, b)	for(unsigned int i=(a);i>(b);--i)
#define _re_rep(i, a, b)	for(unsigned int i=(a);i>=(b);--i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;

// INT_MAX       INT_MIN
// DBL_MAX       DBL_MIN
ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

ll t, cnt;

int main() {
	t = read();
	while (t--) {
		ll l, k, ans = 0;
		string s;
		map<char, int> mp;
		l = read();
		k = read();
		cin >> s;
		_for(i, 0, l) {
			if (mp[s[i]]++ != 0) ans++;
			if (i >= k)	mp[s[i - k]]--;
		}
		cout << "Case " << ++cnt << ": " << ans << endl;
	}
	return 0;
}

 

 

问题 G: Cacho

时间限制: 1 Sec  内存限制: 128 MB

题目描述

In Bolivia there is a very popular game called “Cacho”. The game consists rolling five dices( a1 , a2 , a3 ,a4 , a5 ) and then annotate the result according to certain rules. This time we will focus on one case in particular: “escala”. A “escala” is the scene in which the dices form a sequence of consecutive numbers.
More formally a “escala” meets the property:
ai + 1 = ai+1, 1 ≤ i ≤ 4
There are two types of “escala”: a ordinary “escala” (it satisfy the property described above), and a “Escala Real” (when the scenery is 1, 3, 4, 5, 6. In the game this case is also a valid “scala”).
Cael is a boy who is learning to play and wants you to help develop a program to check when five dices are forming a “escala”. Note that the “Escala Real” is not a valid “escala” for Cael.

输入

The input begins with a number T ≤ 100, the number of test cases. Below are T lines, each with five numbers ai (1 ≤ ai ≤ 6) in no-decreasing order.

输出

In each case, if the five dices form a scale print in one line‘ Y’. Otherwise print in one line ‘N’ (quotes for clarity).

样例输入

5
1 2 3 4 5
2 3 4 5 6
1 4 4 4 5
1 3 4 5 6
1 2 2 3 6

样例输出

Y
Y
N
N
N

 

每行的i:【1,4】满足 lis[i]-1==lis[i-1]。

每行从【1,4】遍历一遍即可。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

int main() {
	ll n;
	n = read();
	ll st[n + 1][6];
	_rep(i, 1, n) {
		bool flag = true;
		_rep(j, 1, 5) {
			st[i][j] = read();
			if (j > 1)	if (st[i][j] != st[i][j - 1] + 1)	flag = false;
		}
		flag ? cout << 'Y' : cout << 'N';
		cout << endl;
	}
	return 0;
}

 

 

问题 J: 超市收银

时间限制: 1 Sec  内存限制: 128 MB

题目描述

小明在一家超市做兼职收银员。恰好在昨天,他使用的电脑突然死机,重启后发现几天的账目都被清空了,在全力恢复数据后,总算找回了所有的每笔交易收入和找零的数据。例如,某笔交易收银机显示应收67元,实收100元,找零33元,这里能恢复的数据就只有100和33。
由于交易数量太多,小明忙了一整天还没有完成,请你帮他写一个程序计算一下所有数据的总收入吧!

输入

第一行输入一个n,表示恢复出来的交易数目。
接下来n行,每行两个整数,表示每笔交易的实收和找零数据。恢复出的数据,不保证实收是前一个数,可以确定的是:实收值肯定不小于找零的值。

输出

输出一个整数,表示n笔交易的收入总值。

样例输入

【样例1】
3
100 20
20 4
41 5
【样例2】
2
10 0
22 5

样例输出

【样例1】
132
【样例2】
27

提示

样例1解释
共3笔交易,第一笔交易实收100,找零20,收入80;第二笔收入20-4=16;第三笔交易41-5=36。三笔交易总收入80+16+36=132
样例2解释
交易2笔,第一笔收入10元,第二笔收入17元。

【数据范围】
70%的数据,n<=1000。
100%的数据,n<=100000,每笔数据的账目数值都不超过1000000

 

简单的减法运算。

收入=收银-找零。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

int main() {
	ll n;
	ll a, b, ans = 0;
	n = read();
	while (n--) {
		a = read();
		b = read();
		ans += abs(a - b);
	}
	cout << ans;
	return 0;
}

 

 

问题 K: 足球联赛

时间限制: 1 Sec  内存限制: 128 MB

题目描述

小明热爱足球,也热爱家乡球队1队。新的一年足球联赛又开始了,共n个球队,进行双循环比赛。双循环比赛是指每个球队与其他n-1只队伍分别踢两场正式比赛,就是主场和客场比赛。如下图,在n=3的情况下,表示3只球队,共6场比赛。

第i行有n-1场比赛,表示球队i所踢的n-1场主场比赛。第i列就是队i的n-1场客场比赛。上表中第一行表示队1在主场4:3战胜了队2,在与队3的对比赛中1:2不敌对手;而客场比赛与队2战成0:0平,又以2:1战胜了队3。
根据足球联赛的得分规则,以双方进球多少评判比赛胜负,比赛战平(进球数一样多),双方各得1分;如果比赛分出胜负,那么获胜方(进球多的)得到3分,输的那方不得分。
队1在主场一胜一负,得到3分,在客场一胜一平,得到4分。队1的总积分为7分。
队2在主场一胜一平,得到4分,在客场一平一负,得到1分,队2的总积分为5分。
队3总得分为4分
因此,队1分数最高,可以获得冠军。联赛规定,若有多个得分最高的队伍,他们将分享冠军的荣誉,同时获得冠军。
现在小明想要知道,在看完并记录下所有比赛后,家乡球队队1能否获得冠军,并计算出队1赛季总积分。

输入

第一行一个整数n,表示参加联赛的球队数量,小明支持的就是队1。
接下来n行,每行n*2个整数,第i行第j对整数表示队i在主场对阵队j的比赛情况,两个整数分别表示主队(队i)和客队(队j)的进球数。当i=j的时候,两个整数用-1表示,自己和自己踢球的情况是不存在的。

输出

若队1夺冠,那么在第一行输出“Yes”;若1队的总积分不是最高的,那么在第一行输出“No”。
第二行输出一个整数,表示队1的赛季总积分。

样例输入

【样例1】
3
-1 -1 4 3 1 2
0 0 -1 -1 3 0
1 2 1 1 -1 -1
【样例2】
2
-1 -1 2 2
3 0 -1 -1

样例输出

【样例1】
Yes
7
【样例2】
No
1

提示

样例2解释
共2个球队,踢2场比赛,第一场队1在主场和队2打成平手,第二场队2在主场3:0战胜队1。队1一平一负积1分,队2一胜一平得4分。队1没有夺冠,积分为1分。

【数据范围】
100%的数据,n<=30,每个球队的进球数量不超过10。
评分标准,输出是否夺冠正确将得到该测试点一半的分数;总积分输出正确,将得到该测试点另一半分数。

 

i、j:i为主场与j的结果。

a、b都为-1时不判断;否则判断胜负,记录i、j的分数(point)。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

double mysqrt(double num, double mi) {
	return pow(num, 1 / mi);
}

int juge(ll a, ll b) {
	if (a == b) return 1;
	if (a > b)   return 2;
	return 3;
}

ll n, a, b;

int main() {
	n = read();
	ll point[n + 1] = {0};
	_rep(i, 1, n) {
		_rep(j, 1, n) {
			a = read();
			b = read();
			if (a != -1 && b != -1) {
				switch (juge(a, b)) {
					case 1: {
						point[i]++;
						point[j]++;
						break;
					}
					case 2: {
						point[i] += 3;
						break;
					}
					case 3: {
						point[j] += 3;
						break;
					}
					case 4: {
						continue;
					}
				}
			}

		}
	}
	if (max_element(point + 1, point + 1 + n) - point != 1) cout << "No";
	else                                                    cout << "Yes";
	cout << endl << point[1];
	return 0;
}

 

 

问题 M: 一箭多雕

时间限制: 1 Sec  内存限制: 128 MB

题目描述

小明喜欢武侠小说,在武侠世界里,他不但练就了一箭双雕的能力,还可以一箭多雕。
现在所有雕在一条直线上从左到右排列,但是他们的高度不同。而小明想要把他们都射下来。小明使用的是一种特殊的弓箭,他可以将弓箭射到任意一个高度为H的雕,当射中一个高度为H的雕后,弓箭的高度会下降到H-1,再从左到右飞行,直到射到高度为H-1的大雕,再降低1的高度,直到飞出大雕的队列。
由于弓箭数量有限,小明想要知道,最少用多少的弓箭,就可以射下所有的大雕。

输入

第一行一个整数,n表示直线上的大雕数量。
第二行n个整数,表示从左到右每个大雕的高度。

输出

输出一个整数,表示最少用的弓箭数量。

样例输入

【样例1】
5
2 1 5 4 3
【样例2】
5
1 2 3 4 5
【样例3】
5
4 5 2 1 4

样例输出

【样例1】
2
【样例2】
5
【样例3】
3

提示

样例1解释
第一箭射向第一个大雕,射中后高度下降到1,会射中第二只大雕。
第二箭射向第三个大雕,依次射中高度为5,4,3的三只大雕。
样例2解释
5只大雕,分别使用1个弓箭。
样例3解释
第一箭射向第一个大雕,射中后高度下降到3。
第二箭射向第二个大雕,射下高度为5和4的大雕。
第三箭射向第三个大雕,射下高度为2和1的大雕。

【数据范围】
30%的数据,n<=5000, 大雕的高度<=10000
70%的数据,n<=1000000, 大雕的高度<=1000000
100%的数据,n<=1000000, 大雕的高度<=1000000000。

 

朴素算法:每次从头寻找一个严格上升子序列,将子序列从母序列中删除。几个子序列就要几支箭。

                  过于暴力,超时。

桶记录:如果当前高度h有有后继(h+1),mp[h+1]--;否则箭+1。

              记录h个数。

               数据范围稍大,存不下,用map。

               map的查找、插入O(logN),时间超限,改用unorder_map,查找、插入O(logN)。

 

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<stack>
#include<map>
#include<list>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#include<limits.h>
#include<float.h>
#define pi 3.14159265358979323846264338327950288419716939937510582097494
using namespace std;
#define _for(i, a, b) for(unsigned int i=(a);i<(b);++i)
#define _rep(i, a, b) for(unsigned int i=(a);i<=(b);++i)
#define _re_for(i, a, b)	for(unsigned int i=(a);i>(b);--i)
#define _re_rep(i, a, b)	for(unsigned int i=(a);i>=(b);--i)
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
const int INF1 = 0x3f3f3f3f;
const int INF0 = 0xc0c0c0c0;

// INT_MAX       INT_MIN
// DBL_MAX       DBL_MIN
ll read() {
	ll x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')      f = -1;
		c = getchar();
	}
	while (isdigit(c))   x = x * 10 + (c - 48), c = getchar();
	return x * f;
}

unordered_map<ll, ll> mp;

int main() {
	ll n, ans = 0, num;
	n = read();

	while (n--) {
		num = read();
		if (mp[num  + 1])	mp[num + 1]--;
		else				ans++;
		mp[num]++;
	}
	cout << ans;
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值