Codeforces Round #324 (Div. 2) A. Olesya and Rodion 构造数字 思维题

来源:互联网 发布:i5处理器编程够用么 编辑:程序博客网 时间:2024/06/06 03:17
A.Olesya and Rodion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.

Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print ?-?1.

Input

The single line contains two numbers, n and t (1?≤?n?≤?1002?≤?t?≤?10) — the length of the number and the number it should be divisible by.

Output

Print one such positive number without leading zeroes, — the answer to the problem, or ?-?1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.

Sample test(s)
input
3 2
output
712
题意:要求构造一个n位数字,使得能被t整除
错因分析:做题的思维僵化,太过“暴力”
AC代码:

#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int main()
{
int n, t;
while (~scanf("%d %d", &n, &t))
{
if (t != 10)
for (int i = 1; i <= n; i++)
cout << t;
else if (n == 1)
cout << "-1" ;
else {
cout << "1";
for (int i = 1; i <= n - 1; i++)
cout << "0";
}
cout << endl;
}
return 0;
}


Wa代码
#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int main()
{
int n,t;
while (~scanf("%d %d",&n,&t))
{
double l = 1en;//10^n,,会编译错误
while (l%t != 0)
l
++;
printf
("%.0f\n", l);
}
return 0;
}


阅读全文
0 0