CSU1327+贪心+模拟
题意简单,中文题目
方法:对于一个数 从左往右找相同的数 ,有就改变靠右的,同时把该数的右边全置0
注意!!!!n<0!!!
1 /* 2 3 */ 4 #include<algorithm> 5 #include<iostream> 6 #include<string.h> 7 #include<stdlib.h> 8 #include<stdio.h> 9 #include<math.h> 10 #include<queue> 11 #include<stack> 12 #include<map> 13 #include<set> 14 using namespace std; 15 typedef long long int64; 16 //typedef __int64 int64; 17 typedef pair<int64,int64> PII; 18 #define MP(a,b) make_pair((a),(b)) 19 const int inf = 0x3f3f3f3f; 20 const double pi=acos(-1.0); 21 const int dx[]={1,-1,0,0}; 22 const int dy[]={0,0,1,-1}; 23 const double eps = 1e-8; 24 const int maxm = 1005; 25 const int maxn = 105; 26 27 int num[ maxn ]; 28 int64 n ; 29 30 void Solve( int cnt ){ 31 int temp = 1; 32 int pos = -1; 33 for( int i=0;i<cnt;i++,temp *= 10 ){ 34 if( i+1<cnt && num[i]==0 && num[i+1]==0 ) continue; 35 if( num[i]==num[i+1] ){ 36 n += temp; 37 pos = i; 38 //printf("pos = %d\n",pos); 39 //printf("i = %d\n",i); 40 if( pos>0 ){ 41 int tt = 1; 42 while( 1 ){ 43 n /= 10; 44 pos--; 45 tt *= 10; 46 if( pos==0 ) break; 47 } 48 n *= tt; 49 } 50 51 if( num[i]==9 ){ 52 int64 nn = n; 53 int cc = 0; 54 while( nn ){ 55 num[ cc++ ] = nn%10; 56 nn /= 10; 57 } 58 } 59 } 60 } 61 //printf("pos = %d\n",pos); 62 } 63 64 bool Judge( int n ){ 65 int cnt = 0; 66 int64 nn = n; 67 while( nn ){ 68 num[ cnt++ ] = nn%10; 69 nn /= 10; 70 } 71 bool flag = true; 72 for( int i=0;i<cnt;i++ ){ 73 if( i+1<cnt && num[i]==0 && num[i+1]==0 ) continue; 74 if( num[i]!=num[i+1] ) {} 75 else { 76 flag = false; 77 break; 78 } 79 } 80 if( flag==true ) 81 return true; 82 Solve( cnt ); 83 return false; 84 } 85 86 int main(){ 87 int T; 88 scanf("%d",&T); 89 while( T-- ){ 90 //scanf("%d",&n); 91 cin>>n; 92 if( n<0 ){ 93 cout<<"0"<<endl; 94 continue; 95 } 96 n ++; 97 memset( num,0,sizeof( num ) ); 98 while( 1 ){ 99 if( Judge(n)==true ) break; 100 } 101 //printf("%d\n",n); 102 cout<<n<<endl; 103 } 104 return 0; 105 }
keep moving...