摘要: http://poj.org/problem?id=2709平摊问题,用贪心算法解决;因为gray可以用任意三种涂料合成,本题的题意就是把gray转换成它的原料(可以是任意三种),再加上以前已经有的,使各种涂漆原料的量尽可能的相近;这样先把每种涂漆按照量的多上进行从小到大排序,每次选择前三个加一,直至gray变为零;#include<iostream>#include<algorithm>using namespace std;int main(){ int n; int color[14]; while(cin>>n&&n!=0) { in 阅读全文
posted @ 2012-04-06 14:55 orangeblog 阅读(320) 评论(0) 推荐(1) 编辑
摘要: 贪心,初始化flag[]数组时不小心错了,还有就是建图的时候错了;这题乍一看感觉有点像最短路径,不过第一感觉不总是对的,尤其像刚出道的我;#include<iostream>#include<queue>using namespace std;int map[100][100];int flag[200];//queue <int> q;//bool operator<(int a,int b)//{// return b<a;//}int main(){ int n; char schar,echar; while(cin>>n&a 阅读全文
posted @ 2012-04-06 10:46 orangeblog 阅读(525) 评论(1) 推荐(0) 编辑