小陈的开学第十二周代码

本文解析了AtCoder平台上的三道经典算法题目,包括税前价格计算、商品组合购买可能性判断以及从幸运数字中生成不同PIN码的方法。通过详细的解题思路和代码示例,帮助读者理解并掌握算法设计和实现技巧。

一、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;
}
关于“Designer 小陈”的具体作品或资料,在当前提供的引用内容中并未提及任何与其直接相关的信息。然而,可以从这些引用的内容推测一些可能的方向来探索其潜在的作品领域。 如果假设“小陈”是一名专注于电子设计自动化(EDA)工具使用的工程师或者开发者,则他可能会涉及如下几个方面的工作: ### 1. **Altium Designer 的应用** 根据相关内容描述[^1],可以推断出“小陈”或许擅长利用 Altium Designer 创建并配置 PCB 文档。这是一款功能强大的 EDA 软件,用于电路板的设计与开发。以下是该方向的一些典型工作成果: - 设计高质量的印刷电路板 (PCB),包括多层板布局、信号完整性分析以及电源管理优化。 - 利用 Altium Designer 提供的功能模块完成从原理图绘制到最终生产文件导出的一系列操作。 - 参考安装指南[^4],能够熟练部署 Altium Designer 并为其设置合适的环境变量以便高效开展项目。 ```python # 示例 Python 脚本片段展示如何通过 API 自动化部分 Altium 工作流程 import altium_api def create_pcb_document(project_name, board_dimensions): new_project = altium_api.Project(project_name) pcb_doc = new_project.add_board(board_dimensions['width'], board_dimensions['height']) return pcb_doc ``` --- ### 2. **解决 Visual Studio 开发中的常见问题** 依据另一条参考资料提到的情况[^2],“小陈”也可能具备处理复杂编程环境中遇到的技术难题的能力。例如当尝试加载某个 UI 文件失败时给出合理解释及解决方案。这种技能表明他对微软生态系统下的软件架构有着深刻理解。 对于此类错误消息:“The designer cannot be shown because the document for it was never loaded”,一般建议采取以下措施排查原因: - 确认目标框架版本是否匹配实际运行条件; - 清理重建整个解决方案以消除残留数据干扰; - 更新至最新版 SDK 或补丁包从而修复已知漏洞; --- ### 3. **图形界面开发经验分享** 最后一条参考文献指出存在两种实现 GUI 应用程序的方式——借助可视化编辑器 Qt Designer 和纯编构建[^3]。“小陈”很可能更倾向于前者,因为这种方法不仅效率高而且灵活性强。凭借这一专长,他应该制作过不少实用型桌面应用程序原型演示视频或是撰写技术博客文章介绍最佳实践案例。 总结而言,虽然目前无法确切得知“Designer 小陈”到底创作了哪些具体的 IT 方面材料,但从上述三个方面可以看出他的兴趣范围广泛涵盖了硬件电路规划、软件调试技巧乃至于交互式前端呈现等多个维度。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值