uva - 10602 - Editor Nottoobad(贪心)
来源:互联网 发布:网络知识竞赛的网址 编辑:程序博客网 时间:2024/06/04 23:14
题意:给你几个单词,第一个单词必须手动打印,后边的单词可以通过“重复最后一个单词”“删除最后的字母”(当然也可以打印)转换得到,求最小的操作次数。
方法:字典序排序+枚举。输出具有一定的迷惑性,千万要注意它说的如果输出有多种,任意输出一种就行。
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); #endifint 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;}
最近A的第一道uva啊希望能来点状态,一天A1~2道。
1 0
- UVA 10602 Editor Nottoobad(贪心)
- uva - 10602 - Editor Nottoobad(贪心)
- uva:10602 - Editor Nottoobad(贪心)
- uva 10602 - Editor Nottoobad(贪心)
- EDITOR NOTTOOBAD - UVa 10602 贪心
- EDITOR NOTTOOBAD uva+贪心
- UVA - 10602 Editor Nottoobad 贪心+暴力
- UVa 10602 - Editor Nottoobad
- UVa 10602 - Editor Nottoobad
- uva 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- UVA 10602 - Editor Nottoobad
- uva 10602 Editor Nottoobad
- UVA 10602 EDITOR NOTTOOBAD
- UVa 10602 - Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- UVA - 10602 Editor Nottoobad
- uva 10602 Editor Nottoobad
- Nginx源码分析-Epoll模块
- 如何成为优秀的驱动开发工程师
- vim中的杀手级插件: vundle
- 求最小公倍数与最大公约数
- Memcache(MC)系列(一)Memcache介绍、使用、存储、算法、优化
- uva - 10602 - Editor Nottoobad(贪心)
- 64位win7平台下,使用C语言通过odbc无法连接MySQL数据库的问题。
- LeetCode之Minimum Depth of Binary Tree
- cocos2d-x2.2 win7创建项目
- 黑马程序员--单例模式
- java-spring事务管理部分代码主要代码
- 前缀和--Openmp
- sci.misc.imread读取数据为空 或者 IOError: decoder zip not available decoder jpeg not available 解决办法
- Cstyle的札记,R&D必读手册,第4篇 Embedded Ethernet Controller