A direct way to address violence. A direct inference x%11 method.
The table can be found to solve the different situations are not to a large extent will appear.
So starting with the L-violence enumeration. The first error value found is output to.
If it more than R is likewise found in the USA-1.
#include <iostream> #include <cstdlib> #include <cstring> #include <string> #include <cstdio > #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map > #define INF 0x3f3f3f3f#pragma COMMENT (linker, "/stack:16777216") #define EPS 1e-6#define ll long longusing namespace s Td;bool judge (ll X) { ll odd=0,even=0,flag=0; while (x>0) { if (flag) { odd+=x%10; flag=0; } else { even+=x%10; flag=1; } x/=10; } return (even-odd==3);} int main () { ll l,r; int t; scanf ("%d", &t); while (t--) { cin>>l>>r; while (l<=r) { if ((l%11==3) ^judge (L)), break ; l++; } if (l>r) printf (" -1\n"); else cout<<l<<endl; } return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
hdu4956 Poor Hanamichi