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;
}
就是给处一个长度不超过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;
}
相关文章推荐
- Codeforces 387C George and Number【思维】
- Codeforces 387C George and Number
- codeforces 387C George and Number(贪心)
- codeforces 387C George and Number
- CodeForces 387C George and Number
- CodeForces 387C George and Number
- Codeforces 387C George and Number(贪心)
- codeforces 387C George and Number
- CodeForces 387C George and Number
- Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)
- CodeForces 387 C. George and Number[贪心]
- George and Number CodeForces - 387C
- CodeForces 768C Jon Snow and his Favourite Number 暴力 空间换时间
- Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)
- Codeforces 653C Bear and Up-Down【暴力】
- Codeforces 467C George and Job(dp)
- CodeForces - 514D :R2D2 and Droid Army(二分、暴力)
- CodeForces 111B - Petya and Divisors- 暴力-数学
- Codeforces_358A_Dima and Continuous Line(排序+暴力)
- Codeforces 27E. Number With The Given Amount Of Divisors (暴力)