CSU1327+贪心+模拟
2013-10-04 00:20
363 查看
题意简单,中文题目
方法:对于一个数 从左往右找相同的数 ,有就改变靠右的,同时把该数的右边全置0
注意!!!!n<0!!!
方法:对于一个数 从左往右找相同的数 ,有就改变靠右的,同时把该数的右边全置0
注意!!!!n<0!!!
/* */ #include<algorithm> #include<iostream> #include<string.h> #include<stdlib.h> #include<stdio.h> #include<math.h> #include<queue> #include<stack> #include<map> #include<set> using namespace std; typedef long long int64; //typedef __int64 int64; typedef pair<int64,int64> PII; #define MP(a,b) make_pair((a),(b)) const int inf = 0x3f3f3f3f; const double pi=acos(-1.0); const int dx[]={1,-1,0,0}; const int dy[]={0,0,1,-1}; const double eps = 1e-8; const int maxm = 1005; const int maxn = 105; int num[ maxn ]; int64 n ; void Solve( int cnt ){ int temp = 1; int pos = -1; for( int i=0;i<cnt;i++,temp *= 10 ){ if( i+1<cnt && num[i]==0 && num[i+1]==0 ) continue; if( num[i]==num[i+1] ){ n += temp; pos = i; //printf("pos = %d\n",pos); //printf("i = %d\n",i); if( pos>0 ){ int tt = 1; while( 1 ){ n /= 10; pos--; tt *= 10; if( pos==0 ) break; } n *= tt; } if( num[i]==9 ){ int64 nn = n; int cc = 0; while( nn ){ num[ cc++ ] = nn%10; nn /= 10; } } } } //printf("pos = %d\n",pos); } bool Judge( int n ){ int cnt = 0; int64 nn = n; while( nn ){ num[ cnt++ ] = nn%10; nn /= 10; } bool flag = true; for( int i=0;i<cnt;i++ ){ if( i+1<cnt && num[i]==0 && num[i+1]==0 ) continue; if( num[i]!=num[i+1] ) {} else { flag = false; break; } } if( flag==true ) return true; Solve( cnt ); return false; } int main(){ int T; scanf("%d",&T); while( T-- ){ //scanf("%d",&n); cin>>n; if( n<0 ){ cout<<"0"<<endl; continue; } n ++; memset( num,0,sizeof( num ) ); while( 1 ){ if( Judge(n)==true ) break; } //printf("%d\n",n); cout<<n<<endl; } return 0; }
相关文章推荐
- 1.一些 贪心算法 的简单思维题:
- Codeforces 193 Div 2
- Sicily 2013. Pay Back
- HDU-1009 FatMouse' Trade
- uva11729
- POJ - 1700 Crossing River【贪心】
- 2013. Pay Back
- ZOJ-1076 Gene Assembly
- ZOJ-1360 Radar Installation
- ZOJ-1877 Bridge
- ZOJ-1756 Robots
- ZOJ-2002 Copying Books
- POJ 1521 熵 定长编码和变长编码的比较(huffman)
- Jump Game
- Jump Game II
- Jump Game (能否到达终点,贪心) 【leetcode】
- Jump Game II (最小步数到达终点,贪心) 【leetcode】
- leetcode:Maximum Subarray(最大的连续子数组) 【面试算法】
- CF 322B Ciel and Flowers 贪心水题
- CF:322D - Ciel and Duel 贪心 或者 DP 我用的贪心 。。难道sort跟qsort是不一样的么?