Codeforces Round #324 (Div. 2) PROBLEM A
来源:互联网 发布:淘宝有平板客户端吗 编辑:程序博客网 时间:2024/05/16 00:39
Codeforces Round #324 (Div. 2) PROBLEM A解题报告
题目链接Here
题意:
输入n, t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10) ;
找出任意一个满足以下条件的数输出即可:该数有n位,且能被t整除,不能以0开头。如果没有满足要求的值就输出-1。
题解:
首先判断输出-1的情况,只有n位数比t还小的情况才有可能不存在符合条件的值。此时n=1,t=10。
对于其它的情况如果t<10,那么只需要输出连续的n个t(必定能整除t)即可。如果t=10,那么只需要保证n位数的最后一位为0,其它n-1位数可以是任意数(不能以0开头)。
因为比赛前刚刚学了< vector >,所以此题我是用< vector >来做的,特意写个题解纪念下。
代码如下:
#include <bits/stdc++.h>using namespace std;int main() { vector<int> v; int n, t; int ans = -1; cin >> n >> t; if (n == 1 && t == 10) { cout << ans << endl; return 0; } if (t != 10) { for (int i = 0; i < n; ++i) v.push_back(t); } else { for (int i = 0; i < n - 1; ++i) v.push_back(2); } if (t == 10) v.push_back(0); for (int i = 0; i != v.size(); ++i) { cout << v[i]; } cout << endl; return 0;}
此题的代码可以不用< vector >(是在下装逼了),直接用个for循环连续输出n个t即可。
0 0
- Codeforces Round #324 (Div. 2) PROBLEM A
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #363 (Div. 2), problem: (A)
- Codeforces Round #401 (Div. 2), problem: (A)
- Codeforces Round #221 (Div. 2) (Problem 376A~C)
- Codeforces Round #230 (Div. 2) problem A(小算数)
- Codeforces Round #FF (Div. 2) Problem A DZY Loves Hash
- Codeforces Round #FF (Div. 2):Problem A - DZY Loves Hash
- contest: Codeforces Round #301 (Div. 2), problem: (A) Combination Lock
- Codeforces Round #295 (Div. 2), problem: (A) Pangram
- contest: Codeforces Round #303 (Div. 2), problem: (A) Toy Cars
- Codeforces Round #298 (Div. 2), problem: (A) Exam
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- Codeforces Round #320 (Div. 2)C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C - A Problem about Polyline
- Codeforces Round #320 (Div. 2) C - A Problem about Polyline
- c++primer学习:泛型算法(2)
- 学习HTML5游戏开发的几个重要内容
- 一个简单的jsp+servlet实例,实现简单的登录
- LightOJ 1074 Extended Traffic SPFA
- Android中一些常见文件格式分析
- Codeforces Round #324 (Div. 2) PROBLEM A
- Read alignment后的质量控制
- Linux系统上低功耗蓝牙遥控器开发项目笔记
- 黑马程序员--Java基础--07-反射
- JavaWeb知识结构图
- 读取字符数组
- 整理学习HTML资料
- 数值优化(Numerical Optimization)学习系列-最小二乘问题(Least-Squares)
- 常用正则表达式