Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

太弱了。做了这么长时间。写的还烂。。

Posted by lagoon0o0 at 2012-07-26 17:03:28 on Problem 1239
#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
struct lint 
{
	int l,r;
	int len;
};
lint INF;
char s[100];
bool vis[100];
lint f[100][100];
bool operator == (const lint &a, const lint &b)
{
	if(a.len != b.len) return false;
	for(int i = a.l,j = b.l; i <= a.r && j <= b.r; i++,j++)
	if(s[i] != s[j])
	return false;
	return true;
}
bool operator < (const lint &a, const lint &b)
{
	if(a.len != b.len) return a.len < b.len;
	for(int i = a.l,j = b.l; i <= a.r && j <= b.r; i++,j++)
	if(s[i] != s[j])
	return s[i] < s[j];
	return s[a.l] < s[b.l];
}
inline lint get(int l , int r)
{
	lint res;
	while(l < r && s[l] == '0') l++;
	res.l = l;
	res.r = r;
	res.len = r-l+1;
	return res;
}
inline void find(int i, int j)
{
	if(i == 0) return;
	for(int k = j-1;k >= 1; k--)
	if(f[i-1][k] < f[i][j] && get(k+1,j) == f[i][j])
	{
		vis[k] =true;
		find(i-1,k);
		return;
	}
}
int main()
{
	INF.len = 1000;
	INF.l = INF.r = 0;
	while(1)
	{
		memset(vis,false,sizeof vis);
		scanf("%s",s+1);
		int n = strlen(s+1);
		if(n==1 && s[1] == '0') break;
		for(int i = 0; i <= n; i++)
			for(int j = 0; j <= n; j++)
				f[i][j] = INF;

		f[0][0].len = -100;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				for(int k = 0;k < n; k++)
				if(f[i-1][k].len != 1000)
				{
					lint now = get(k+1,j);
					if(f[i-1][k] < now)
						f[i][j] = f[i][j] < now ? f[i][j] : now;
				}
		int k;
		lint ans = INF;
		for(int i = 1; i <= n; i++)
		if(f[i][n] < ans)
		{
			ans = f[i][n];
			k = i;
		}
		find(k,n);
		for(int i = 1; i <= n; i++)
		{
			putchar(s[i]);
			if(vis[i])
				putchar(',');
		}
		puts("");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator