您的位置:首页 > 其它

Codeforces 387C George and Number 暴力

2015-02-26 23:09 295 查看
题目大意:

就是给处一个长度不超过10^5的十进制正整数, 是按照题目所给的方法从一个数组中拼出来的

为初始的那个数组最多有多少个元素

大致思路:

就是一个很简单的暴力枚举, 每次后面截下的一段数尽量小即可

代码如下:

Result  :  Accepted     Memory  :  100 KB     Time  :  31 ms

/*
* Author: Gatevin
* Created Time: 2015/2/26 22:43:33
* File Name: poi~.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;

/*
* 一个简单的贪心的想法就是从后边拆出来的数尽量小
* 然后暴力枚举剩余的串后面从哪个位置开始断开即可
*/
char s[100010];

bool compare(int s1, int e1, int s2, int e2)//比较起始位置s1种植位置e1和起始位置s2, 终止位置e2的串之间的大小
{
int len1 = e1 - s1 + 1;
int len2 = e2 - s2 + 1;
if(len2 < len1) return true;
if(len2 > len1) return false;
for(int i = 0; i < len1; i++)
if(s[s1 + i] > s[s2 + i]) return true;
else if(s[s1 + i] < s[s2 + i]) return false;
return true;//相等了
}

int main()
{
int pos = 0;
scanf("%s", s);
int n = strlen(s);
int end2 = n - 1;
int end1 = n - 2;
while(end2 >= 0)
{
while(end1 >= 0 && (s[end1 + 1] == '0' || !compare(0, end1, end1 + 1, end2)))
end1--;
if(end1 == -1)
break;
pos++;
end2 = end1;
end1--;
}
pos++;
cout<<pos<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息