UPC 2020年秋季组队训练赛第十四场

问题 A: Too Expensive to Buy a House
时间限制: 1 Sec 内存限制: 128 MB

题目描述
WNJXYK and DIDIDI are good friends . One day, WNJXYK found DIDIDI bought a house, so he also wanted to buy a house. Because the price of house is rising continuously, so WNJXYK hope that he can buy a house before he couldn’t afford it. Currently, a house need $A, the price increases by $B per mouth, and WNJXYK only have a deposit of $C. Your assignment is to calculate in how many months should WNJXYK buy the house before he couldn’t afford it.

输入
The first line of input contains a positive integer T telling you there are T test cases followed.
Each test case will contain 3 integers, A, B, C.
输出
For each test case, print a line “Case #x: y”, where x is the case number (starting from 1) and y is an integer indicating the number of months.

样例输入
3
1 2 3
1 2 6
1 2 1
样例输出
Case #1: 1
Case #2: 2
Case #3: 0

提示
Tips:1≤T≤20,1≤A≤C≤1e9, 1≤B≤1e6
Case 1: after 1 month, price will be 3
Case 2: after 2 months, price will be 5, after 3 months, price will be 7, and he can’t afford it.
Case 3: after 1 month, price will be 3, he can’t afford it.

这题直接看题目就行了,数据都不需要看,题意:某人想买房子,房子的基本价格为A,每个月还会上涨B,某人有C元,问最多能到第几个月还能买得起。就是一个整除问题,公式:(C-A)/B。时间复杂度几近O(1),直接暴力即可。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t,a,b,c,ans;
 
int main()
{
    
    
    cin>>t;
    for(int i=1; i<=t; i++)
	{
    
    
        cin>>a>>b>>c;
        ans = (c-a)/b;
        printf("Case #%d: %d\n", i, ans);
    }
    return 0;
}

问题 B: WNJXYK loves to take a shower
时间限制: 1 Sec 内存限制: 128 MB

题目描述
WNJXYK often takes a shower in school public bathroom. The bathroom has many cabinets. WNJXYK found that the number of the cabinet is strange. No number contains digit ‘4’, in other words, numbers like ‘14’,’34’,’456’ don’t exist. So cabinet 5 is actually the 4th cabinet. We know WNJXYK’s number is N. Your assignment is to calculate his cabinet’s real number.

输入
The first line of input contains a positive integer T telling you there are T test cases followed.
Each test case will contain one integer.
输出
For each test case, print a line “Case #x: y”, where x is the case number (starting from 1) and y is an integer indicating real number of WNJXYK’s cabinet.

样例输入
2
5
15
样例输出
Case #1: 4
Case #2: 13

提示
Tips:1≤T≤20,1≤N≤10000
Case 1: 1 2 3 5
Csse 2: 1 2 3 5 6 7 8 9 10 11 12 13 15

多组数据,每组输出n减去1~n中含有4的数字的数目。重点操作:sprintf(str,“%d”, i)—— 数字转字符串

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t,n,a[10010];

bool f(int i)  //判断1~n中的某个数转化为字符后,是否含有4 
{
    
    
	char s[8];  //因为n<=10000,所以开8位足够了 
	sprintf(s,"%d",i);  //某个数转化为字符
	
	for(int i=0; i<strlen(s); i++)
		if(s[i]=='4')  return false;  //有4则没number 
	
	return true;
}

int main()
{
    
    
	//可以事先进行预处理,降低复杂度 
	int cnt = 0; 
	for(int i=1; i<=10000; i++)
	{
    
    
		if(f(i))  cnt++;
		a[i] = cnt;
	}
	 
	cin>>t;	
	for(int i=1; i<=t ;i++)
	{
    
    
		cin>>n;
		printf("Case #%d: %d\n",i,a[n]);
	}
	return 0;
}

问题 E: shovel snow
时间限制: 1 Sec 内存限制: 128 MB

题目描述
Northeast China snows every year, so school asks freshmen to shovel snow. This tradition lasts for many years. This year WNJXYK becomes the principle, he thinks that asking freshmen to shovel snow every year is boring, so he hopes that the grade who shovel snow can be different every year. The number of the grades is N, in order to illustrate, we assume N=5 here. WNJXYK hopes that in every 5-year, grade 1 shovels snow in the first year, grade 2 the second year, grade 3 the third year, and so on. We can use a permutation 12345 to express it. But in this circumstance DIDIDI find a problem that the grade 1 in the first year is exactly the grade 2 in the second year, so this grade shovels snow for many times in fact.
So DIDIDI use a permutation 13524, that is, first year - grade 1, second year – grade 3, third year – grade 5, fourth year – grade 2, fifth year – grade 4. In this case, every grade need to shovel snow exactly once. In more detail, we assume the first year is 2015. The grade 1 in first year is The Class of 2015. The grade 3 in second year is The Class of 2014. The grade 5 in third year is The Class of 2013. The grade 2 in forth year is The Class of 2017. The grade 4 in fifth year is The Class of 2016. So every grade need to shovel snow exactly once.
For every N given, you need to give a permutation with length N, which can satisfy the requirement that every grade shovels snow exactly once. If there are multiple answers, please give the one with the largest lexicographical order.

输入
The first line of input contains a positive integer T telling you there are T test cases followed.
Each test case will contain one integer N .
输出
For each test case, print two lines.
The first line is “Case #x:”, where x is the case number (starting from 1)。
The second line contains n integers, indicating a n-permutation. If threr is no answer, print “-1”.

样例输入
1
3
样例输出
Case #1:
3 2 1

提示
Tips:1≤T≤20,1≤N≤10000
Case 1: we assume the first year is 2015. The grade 3 in first year is The Class of 2013. The grade 2 in second year is The Class of 2015. The grade 1 in third year is The Class of 2017. The grade 3 in fourth year is The Class of 2016. The grade 2 in fifth year is The Class of 2018. The grade 1 in sixth year is The Class of 2020. The grade 3 in seventh year is The Class of 2019. And so on.

找规律…奇偶数对应相应的输出。

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 10010;
int t,n;
 
int main()
{
    
    
    cin>>t;
    for(int i=1; i<=t; i++)
	{
    
    
        cin>>n;
        printf("Case #%d:\n", i);
        
        if(!(n%2))  cout<<"-1"<<endl;
        else 
		{
    
    
            for(int i=n; i>1; i--)  cout<<i<<" ";
            cout<<"1"<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Luoxiaobaia/article/details/108908097