Codeforces Round #723 (Div. 2)
B. I Hate 1111
题目地址:https://codeforces.com/contest/1526/problem/B
题目大意:给你一个数x,问这个x能不能由11,111,1111 … 111111111…中任意个数组成?如144=111+11+11+11。
思路:首先我们可以发现1111=1110+11,11111=11100+11,111111=1111100+11,所以题目转变成x能否由若干个11和111组成,由此可以列出式子A11+B111=X,其A>=0,B>=0,再设B=C11+D,C>=0,0<=D<=10,整理一下X=11*(C111+A)+D111,所以穷举所有的D判断等式是否成立即可。
代码:
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
inline int read()
{
int x=0,y=1;
char ch;
ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')y=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*y;
}
int main()
{
int t,x,flag;
t=read();
while(t--)
{
x=read();
flag=1;
for(int i=0;i<=10;i++)
{
if((x-i*111>=0)&&(x-i*111)%11==0)
{
cout<<"YES"<<endl;
flag=0;
break;
}
}
if(flag)cout<<"NO"<<endl;
}
return 0;
}