首页 > 其他 > 详细

uva - 10602 - Editor Nottoobad(贪心)

时间:2014-03-25 03:18:07      阅读:380      评论:0      收藏:0      [点我收藏+]

题意:给你几个单词,第一个单词必须手动打印,后边的单词可以通过“重复最后一个单词”“删除最后的字母”(当然也可以打印)转换得到,求最小的操作次数。

方法:字典序排序+枚举。输出具有一定的迷惑性,千万要注意它说的如果输出有多种,任意输出一种就行。

AC代码:

#include <iostream>    
#include <iomanip>    
#include <string>    
#include <cstring>    
#include <cstdio>    
#include <queue>    
#include <stack>    
#include <algorithm>    
#include <cmath>    
#include <ctime>

using namespace std;  
const int maxn = 100+10;

void Solve(string *word, int N, int ans)
{
	int i = 0, j = 0;
	sort(word, word+N);
	ans = word[0].size();
	for (i = 1; i < N; i++)
	{
		if (word[i][0] != word[i-1][0])
			ans += word[i].size();
		else
		{
			for (j = 0; j < word[i].size() && j < word[i-1].size(); j++)
			{
				if (word[i][j] != word[i-1][j])
					break;
			}
			ans += word[i].size() - j;
		}
	}
	cout << ans << endl;
	for (i = 0; i < N; i++)
		cout << word[i] << endl;
}


int main()
{
#ifdef Local      
	freopen("a.in", "r", stdin);  
#endif
	int T = 0;
	cin >> T;
	while (T--)
	{
		int N = 0, i = 0, ans = 0;
		string word[maxn];
		cin >> N;
		for (i = 0; i < N; i++)
			cin >> word[i];
		Solve(word, N, ans);
	}
	return 0;
}

bubuko.com,布布扣

最近A的第一道uva啊希望能来点状态,一天A1~2道。

uva - 10602 - Editor Nottoobad(贪心),布布扣,bubuko.com

uva - 10602 - Editor Nottoobad(贪心)

原文:http://blog.csdn.net/u013545222/article/details/21994955

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!