小陈的开学第十二周代码

一、Atcoder

1.Tax Rate

题意

Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it.

The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X×1.08 yen (rounded down to the nearest integer).

Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer.

If there are multiple possible values for X, find any one of them. Also, Takahashi’s memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.

输入

Input is given from Standard Input in the following format:

N

输出

If there are values that could be X, the price of the apple pie before tax, print any one of them.
If there are multiple such values, printing any one of them will be accepted.
If no value could be X, print : ( .

样例输入1

432

样例输出1

400

If the apple pie is priced at 400 yen before tax, you have to pay 400×1.08=432 yen to buy one.Otherwise, the amount you have to pay will not be 432 yen.

样例输入2

1079

样例输出2

:(

There is no possible price before tax for which you have to pay 1079 yen with tax.

样例输入3

1001

样例输出3

927

If the apple pie is priced 927 yen before tax, by rounding down 927×1.08=1001.16, you have to pay 1001 yen.

解题思路

刚开始以为必须要整除才可以,后来才知道四舍五入就可以了。

程序代码

#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	float n=x/1.08;
	int n1=x*100/108;
	if(n==n1){
		printf("%d\n",n1);
	}else{
		int n2=(n1+1)*1.08;
		if(n2==x){
			printf("%d\n",n1+1);
		}else{
			printf(":(\n");
		}
	}
	return 0;
} 

2.100 to 105

题意

AtCoder Mart sells 1000000 of each of the six items below:

Riceballs, priced at 100 yen (the currency of Japan) each
Sandwiches, priced at 101 yen each
Cookies, priced at 102 yen each
Cakes, priced at 103 yen each
Candies, priced at 104 yen each
Computers, priced at 105 yen each
Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible.(Ignore consumption tax.)

输入

Input is given from Standard Input in the following format:

X

输出

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

样例输入1

615

样例输出1

1

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

样例输入2

217

样例输出2

0

No set of items costs 217 yen in total.

解题思路

跟硬币问题很像,但是仔细一看又觉得不能用贪心,刚开始我就用dfs写的,后来交了超时了,可能我还写错了,后来跟着某人的思路,用了贪心,很复杂的贪心,先要%100,然后用54321进行贪心,但是所用的次数不能超过x/100,否则就不行,改了好几次才对。

程序代码

#include<bits/stdc++.h>
using namespace std;
const int a[6]={0,1,2,3,4,5};
int main(){
	int x;
	cin>>x;
	int n=x/100;
	x=x%100;
	int cnt=0;
	for(int i=5;i>=0;i--){
		cnt+=(x/a[i]);
		x=x-a[i]*(x/a[i]);
		if(x==0) break;
	}
	if(cnt>n){
		printf("0\n");
		return 0;
	}
	if(x==0){
		printf("1\n");
	}else{
		printf("0\n");
	}
	return 0;
}

3.Lucky PIN

题意

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N−3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

输入

Input is given from Standard Input in the following format:

N
S

输出

Print the number of different PIN codes Takahashi can set.

样例输入1

4
0224

样例输出1

3

Takahashi has the following options:
Erase the first digit of S and set 224.
Erase the second digit of S and set 024.
Erase the third digit of S and set 024.
Erase the fourth digit of S and set 022.
Thus, he can set three different PIN codes: 022, 024, and 224.

样例输入2

6
123123

样例输出2

17

样例输入3

19
3141592653589793238

样例输出3

329

程序代码:(别人的)

#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	string s;
	while(cin >> n >> s){
		int ans = 0;
		for(int i = 0; i <= 9; i++){
			int t = 0;
			while(t < n){
//				cout << t << endl;
				if(s[t++] == i + '0') break;
			}
			if(t < n){
				for(int j = 0; j <= 9; j++){
					int y = t; 
					while(y < n)
						if(s[y++] == j + '0') break;
					if(y < n){
						for(int k = 0; k <= 9; k++){
							int z = y;
							while(z < n)
								if(s[z++] == k + '0') break;					
							if(z <= n && s[z-1] == k + '0'){
								ans++;
		//						cout << i <<" " << j << " " << k << endl;
							} 
						}				
					}
				}				
			}

		}
		cout << ans << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值