File Fragmentation 贪心+分治 uva
来源:互联网 发布:政府与网络 编辑:程序博客网 时间:2024/06/06 12:33
/*题意是将文件还原。n分文件摔成了2*n份,其中每一对都对应一份源文件。求原文件。这题的写法充分展示了c++的优势,其中的string【n】的用法,和定义的string排序。从中间分开,前后进行搜索。*/#include <iostream>#include <stdio.h>#include <string>#include <algorithm>#include <cstring>using namespace std;string s[270];string tmp;bool vis[270];bool cmp(string a,string b){ return a.length()>b.length();}int h;bool judge(string a){ for(int i=0;i<(h+1)>>1;i++) { bool flag=false; vis[i]=true; for(int j=h-1;j>i;j--) { if(!vis[j]&&s[i]+s[j]==a) { vis[j]=true; flag=true; break; } } if(!flag) return false; } return true;}int main(){ char ss[270]; while(gets(ss)) { s[0]=ss; h=1; while(gets(ss)) { if(ss[0]=='\0') break; s[h++]=ss; } sort(s,s+h,cmp); bool found=false; for(int i=h-1;i>=0&&s[i].length()==s[h-1].length();i--) { tmp=s[0]+s[i]; memset(vis,false,sizeof(vis)); if(judge(tmp)) { found=true; cout << tmp << endl; break; } } if(!found) cout << s[0]+s[h-1] << endl; } return 0;}
- File Fragmentation 贪心+分治 uva
- File Fragmentation+uva+贪心
- UVa 10132 - File Fragmentation 贪心+枚举
- uva - 10132 - File Fragmentation(贪心)
- UVA - 10132 File Fragmentation(贪心)
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- uva 10132 - File Fragmentation
- uva 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVa 10132 - File Fragmentation
- UVA 10132 File Fragmentation
- UVa:10132 File Fragmentation
- UVA 10132 - File Fragmentation
- uva 10132 File Fragmentation
- uva 10132 File Fragmentation
- uva 10132 File Fragmentation
- c++ vector 释放内存
- Set Partition Algorithm(集合划分算法)
- openGL中camera类的设计以及使用
- git+openssh 的安装与简单使用
- OpenCV(EmguCV)2.1新特性介绍之图像分割GrabCut(GrabCut Of OpenCV 2.1)
- File Fragmentation 贪心+分治 uva
- ext.net StoreProxy localstore sessionstore的区别
- html <textarea>出现乱码
- jquery 学习笔记
- (记下,准备翻译)Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase vs Membase vs Neo4j comparison
- 颜色直方图的计算、显示、处理、对比及反向投影(How to Use Histogram? Calculate, Show, Process, Compare and BackProject)
- poj1364 - King
- 经典算法书籍推荐
- 轮廓的查找、表达、绘制、特性及匹配(How to Use Contour? Find, Component, Construct, Features & Match)