https://codeforces.com/contest/1526/problem/B
input
3
33
144
69
output
YES
YES
NO
题意
给T,T循环,给n,是否能用11,111,1111…组成n,能则"YES“.
题目短小精悍,脑子不断死机,看了daolao代码才搞懂。
首先明白最小单元为:11,111,因为1111,11111等都可以由11,111组成,所以只用看能不能用11,111组成
投机取巧法(看别人代码的)
暴力,能11取余就”yes“,不行就减111,直到小于0,就”no“
os:woc这也能卡,为什么数据中最多只有20个111,服
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve();
int main()
{
int t;
cin >> t;
while (t--)
solve();
return 0;
}
void solve()
{
int n, i;
cin >> n;
for (i=0; i<20; i++)
{
if (n%11==0)
{
cout << "YES\n";
return;
}
n -= 111;
if (n < 0)
break;
}
cout << "NO"<<endl;
}
法2
具体详解在下图
#include<iostream>
#include<cstdio>
using namespace std;
void solve()
{
int n;
scanf("%d",&n);
int a=n/110;
int b=n%11;
if(a<b)
printf("NO\n");
else
printf("YES\n");
}
int main()
{
int T;
cin>>T;
while(T--)
{
solve();
}
}
个人理解哈,有问题请指正