HUSTOJ第十五场补题赛

HUSTOJ第十五场补题赛

问题 A: Programming Education

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

题目描述
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.
One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A,B and prints A+B.
Takahashi, who is taking this exam, suddenly forgets his age.
He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A,B and prints A+B if N=2.
Write this program for him.

Constraints
·N is 1 or 2.
·A is an integer between 1 and 9 (inclusive).
·B is an integer between 1 and 9 (inclusive).
输入
Input is given from Standard Input in one of the following formats:
1
或者
2
A
B
输出
If N=1, print Hello World; if N=2, print A+B.
样例输入 Copy
1
样例输出 Copy
Hello World

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	if(n == 1)
		cout << "Hello World" << endl;
	else
	{
		int a = 0;
		int b = 0;
		cin >> a >> b;
		cout << a + b << endl;		
	}
	
	return 0;
}

问题 B: Time Limit Exceeded

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

题目描述
When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time ti at cost ci.
Find the smallest cost of a route that takes not longer than time T.
Constraints
All values in input are integers.
1≤N≤100
1≤T≤1000
1≤ci≤1000
1≤ti≤1000
The pairs (ci,ti) are distinct.

输入
Input is given from Standard Input in the following format:

N T
c1 t1
c2 t2
:
cN tN

输出
Print the smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print TLE instead.
样例输入
3 70
7 60
1 80
4 50
样例输出
4
提示
The first route gets him home at cost 7.
The second route takes longer than time T=70.
The third route gets him home at cost 4.
Thus, the cost 4 of the third route is the minimum.

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n = 0; int t = 0;
	cin >> n >> t;
	
	int res = INT_MAX;
	int flag = 0;
	
	for(int i = 0; i < n; ++i)
	{
		int a = 0; int b = 0;
		cin >> a >> b;
		if(b <= t)
		{
			res = min(res, a);
			flag = 1;
		}
	}
	
	if(flag)
		cout << res << endl;
	else
		cout << "TLE" << endl;
	
	
	return 0;
}

问题 C: Pyramid

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

题目描述
In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.
The pyramid had center coordinates (CX,CY) and height H. The altitude of coordinates (
X,Y) is max(H−|X−CX|−|Y−CY|,0).
Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:
·CX,CY was integers between 0 and 100 (inclusive), and H was an integer not less than
1.
·Additionally, he obtained N pieces of information. The i-th of them is: “the altitude of point (xi,yi) is hi.”
This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints
·N is an integer between 1 and 100 (inclusive).
·xi and yi are integers between 0 and 100 (inclusive).
·hi is an integer between 0 and 109 (inclusive).
·The N coordinates (x1,y1),(x2,y2),(x3,y3),…,(xN,yN) are all different.
·The center coordinates and the height of the pyramid can be uniquely identified.

输入
Input is given from Standard Input in the following format:

N
x1 y1 h1
x2 y2 h2
x3 y3 h3
:
xN yN hN
输出
Print values CX,CY and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.
样例输入
4
2 3 5
2 1 5
1 2 5
3 2 5
样例输出
2 2 6
提示
In this case, the center coordinates and the height can be identified as (2,2) and 6.
思路:数据量不大可以暴力穷举

#include<bits/stdc++.h>
using namespace std;

typedef struct Node
{
	int x = 0;
	int y = 0;
	int h = 0;
} Node;

int main()
{
	vector<Node> nodes;
	int n = 0;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		Node node;
		cin >> node.x >> node.y >> node.h;
		nodes.push_back(node);
	}
	
	int temp = 0;
	while(nodes[temp].h == 0) ++temp;//跳转到高度不为0的点
	
	for(int i = 0; i <= 100; ++i)
	{
		for(int j = 0; j <= 100; ++j)
		{
			int H = nodes[temp].h + abs(nodes[temp].x - i) + abs(nodes[temp].y - j);
			for(int k = 0; k < n; ++k)
			{
				if(nodes[k].h != max(H - abs(nodes[k].x - i) - abs(nodes[k].y - j), 0)) break;
				if(k == n - 1)
				{
					cout << i << " " << j << " " << H << endl;
					return 0;
				}
			}
		}
	}
	
	return 0;
}

问题 D: JP Partition

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

题目描述
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a1+a2+…+aN = M. Find the maximum possible value of the greatest common divisor of a1,a2,…,aN.

Constraints
·All values in input are integers.
·1≤N≤105
·N≤M≤109
输入
Input is given from Standard Input in the following format:

N M
输出
Print the maximum possible value of the greatest common divisor of a sequence a1,a2,…,aN that satisfies the condition.

样例输入 Copy
3 14
样例输出 Copy
2
提示
Consider the sequence (a1,a2,a3)=(2,4,8). Their greatest common divisor is 2, and this is the maximum value.

#include<iostream>
#include<vector>
using namespace std;

int main()
{
	int n = 0; int m = 0;
	
	cin >> n >> m;
	
	for(int i = m / n; i >= 1; --i)
	{
		if(m % i == 0 && m / i >= n)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}

问题 G: 面试

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

题目描述
牛牛内推了好多人去牛客网参加面试,面试总共分四轮,每轮的面试官都会对面试者的发挥进行评分。评分有A B C D四种。如果面试者在四轮中有一次发挥被评为D,或者两次发挥被评为C,就不会通过面试。如果面试者没有一次被评为D,并且有三个或以上的A则会获得special offer。其余情况会获得普通offer。
现在告诉你一些面试者的发挥,请你算一算,他们的面试结果分别是什么。
输入
第一行输入一个T,代表面试者的个数。
接下来有T行,每行都有一个长度为4的字符串,每个位置的字符分别代表面试者每一轮的发挥。
输出
输出T行,分别表示T个面试者的面试结果。如果面试失败,输出failed,如果面试通过,但不是special offer,则输出offer,否则输出sp offer。
样例输入
2
AAAB
ADAA
样例输出
sp offer
failed

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	while(n--)
	{
		string s;
		cin >> s;
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(char i : s)
		{
			if(i == 'A') a++;
			if(i == 'B') b++;
			if(i == 'C') c++;
			if(i == 'D') d++;
		}
		
		if(d || c >= 2)
		{
			cout << "failed" << endl;
		}
		else if(d == 0 && a >= 3)
		{
			cout << "sp offer" << endl;
		}
		else
		{
			cout << "offer" << endl;
		}
	}
	

	return 0;
}

问题 H: 纸牌游戏

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

题目描述
公司举办团建活动,许多人在一起玩一个纸牌游戏。规则如下:总共有n个人,每个人初始有n张牌。每一轮从第一个人开始轮流操作,第i个人每次操作可以选择至多ai个不同的人,分别从他们手中拿走一张牌。手上没有牌的人立即被淘汰出局。大家都不希望自己出局,并且希望有尽可能多的人出局,游戏无限的进行下去,问最终游戏中最少还有几个人没有出局。
输入
第一行输入一个数字n,代表游戏的总人数。接下来输入n个数字,分别代表ai
输出
输出一行一个整数表示游戏最终最少剩几个人。
样例输入
2
1 2
样例输出
2
提示
样例解释:两个人只能互相拿对方的一张牌,游戏永远进行下去。
【数据范围】
对于20%的数据,满足n≤2;
对于40%的数据,满足n≤3;
对于100%的数据,满足1≤n≤105,1≤ai≤109。
思路:贪心

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n = 0;
	cin >> n;
	vector<int> num(n + 1, 0);
	for(int i = 1; i <= n; ++i)
	{
		cin >> num[i];
	}
	
	sort(num.begin(), num.end());
	
	for(int i = 1; i <= n; ++i)
	{
		if(num[i] >= n - i)
		{
			cout << n - i + 1 << endl;
			break;
		}
	}
	
	return 0;
}

问题 I: 涨薪

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

题目描述
公司中总共有n个人,其中第i个人的初始工资为ai。公司根据每个人的绩效(工作表现)来评定每个人的涨薪幅度。每年有x个人绩效为A,工资可以变为原来的3倍;y个人绩效为B,工资可以变为原来的2倍,其余人绩效为C,
工资不变,连续两年绩效为C会被开除。(保证x+y≤n)
假如公司没有一直招聘新员工,请问m年后,公司需要给所有在职员工支付的工资总和最多为多少。由于答案可能很大,请输出对109+7取模后的结果。
输入
输入第一行包含四个正整数n,m,x,y,意义如题面所示。
接下来一行包含n个正整数,第i个正整数为ai代表第i个人的初始工资。
输出
输出一行一个整数表示m年后工资总和对109+7取模后的结果。
样例输入
【样例1】
2 1 1 1
5 3
【样例2】
2 2 0 0
5 2
样例输出
【样例1】
21
【样例2】
0
提示
对于20%的数据范围,满足n≤10,m≤10,ai≤10
对于40%的数据范围,满足n≤105,m≤10,ai≤105
对于另外20%的数据范围,满足n≤105,m≤10,ai≤105且x+y=n
对于另外20%的数据范围,满足n≤105,m≤109,ai≤105且x+y=n
对于100%的数据范围,满足1≤n≤105,1≤m≤109,1≤ai≤105
思路:快速幂+贪心,钱多的拿去涨薪,其余的单独计算即可

#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll; 

const ll mod = 1000000007;

bool cmp(ll a, ll b)
{
	return a > b;
}

ll qpow(ll a, ll n)
{
    ll ans = 1;
    while(n)
	{
        if(n & 1)      
            ans = (ans * a) % mod;
        a = (a * a) % mod;      
        n >>= 1;     
    }
    return ans;
}

int main()
{
	int n = 0; int m = 0; int x = 0; int y = 0;
	
	cin >> n >> m >> x >> y;
	
	vector<ll> num(n, 0);
	
	for(ll i = 0; i < n; ++i) cin >> num[i];
	
	sort(num.begin(), num.end(), cmp);
	
	ll a = 0; ll b = 0;
	ll up_sum = 0; ll sum = 0;
	
	a = qpow(3, m);
	b = qpow(2, m);
	
	for(int i = 0; i < x; ++i)
		up_sum = (up_sum + a * num[i]) % mod;
	for(int i = x; i < x + y; ++i)
		up_sum = (up_sum + b * num[i]) % mod;
	for(int i = x + y; i < n; ++i)
		sum = (sum + num[i]) % mod;
	
	if(m >= 2)
		cout << up_sum % mod << endl;
	else
		cout << (up_sum + sum) % mod << endl;
	
	return 0;
}

问题 J: 变换(未AC)

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

题目描述
给出一个序列A,其中第i个数字为ai,你每次可以选择一个数字不变,将其他数字全部乘以x。其中x为任意素数。
无需考虑这些数字在变换过程中是否超过long long的存储范围。请回答:最少经过多少次操作,可以使得序列中所有数字全部相同。
输入
第一行包含一个正整数n,代表序列长度。
接下来一行包含n个正整数,描述序列中的每一个元素。
输出
输出一行一个正整数表示答案。
样例输入 Copy
2
5 7
样例输出 Copy
2
提示
样例说明:
可以选中第二个数字不变,将第一个数字除以5,然后选中第一个数字不变,将第二个数字除以7。两次操作后,数组中所有数字均变为1。当然还有其他方法,如将两个数字最终都变为35也只需要2次操作。
【数据范围】
对于20%的数据,满足n=2,ai≤106
对于40%的数据,满足n≤10,ai≤106
对于另外20%的数据,满足n≤4∗104,ai≤20
对于100%的数据,满足1≤n≤106,1≤ai≤106
PS:代码超时了,暂时没想到更好的优化办法

#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;

ll read()
{
    ll ans = 0;
    char c = getchar();
    while (!isdigit(c))
        c = getchar();
    while (isdigit(c))
    {
        ans = ans * 10 + c - '0';
        c = getchar();
    }
    return ans;
}

int main()
{
	ll n = read();
	
	vector<ll> num(n, 0);
	ll temp = 0;
	for(ll i = 0; i < n; ++i)
	{
		num[i] = read();
		
		if(i == 0) 
			temp = num[0];
		else
			temp = __gcd(temp, num[i]);
	}
	
	ll cnt = 0;
	
	for(ll i = 0; i < n; ++i)
	{
		num[i] /= temp;
		for(ll j = 2; j * j <= num[i]; ++j)
		{
			if(num[i] % j == 0)
			{
				cnt = num[i] / j;
			}
		}
		if(num[i] > 1) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

总结:比赛时A了五道题,因为吃饭的原因晚了十分钟,第二天又要打ACM就没把时间打完(感觉打满时间五道题也差不多了233),排名还行,这次对于数论考查较多,金字塔那道题A的我云里雾里,补题赛还有两道题没能补上,看了大佬的代码确实没理解到,功力还不够深厚吧,下来还要多下工夫。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值