随笔分类 -  贪心

摘要:高精度阶乘#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn=50000; int s[maxn]; int n; int main() { while(cin>>n) { int i,j,t,k; memset(s,0,sizeof(s)); s[0]=1; int c,l=1; if(n==0||n==1) printf("1"); else { for(i=2;i<=n;i++) { 阅读全文
posted @ 2013-01-25 22:41 LJ_COME!!!!! 阅读(129) 评论(0) 推荐(0)
摘要:贪心,刚做此题时,就意识到了是贪心,但贪心思路一直没找对,wa了n次,在纠结中终于想出正确的思路#include <iostream> #include <algorithm> #include <cstdio> using namespace std; struct node { int x,y; }; node f[25]; bool cmp(node a,node b) { return a.y*b.x<b.y*a.x; } int main() { int n; while(cin>>n) { int i; long long am 阅读全文
posted @ 2012-12-23 00:40 LJ_COME!!!!! 阅读(145) 评论(0) 推荐(0)
摘要://枚举+贪心+优先队列 //最有的方案肯定是从起点走到某个点终止,然后在这条路上通过贪心选择最优的选择(每个点应停留的时间)。最后通过比较得出最优的方案 #include <iostream> #include <queue> #include <cstdio> #include <cstring> using namespace std; const int maxn=26; int t_spent[maxn],eve[maxn][maxn],cost[maxn],d[maxn]; int n,h; struct node { int num 阅读全文
posted @ 2012-12-21 17:13 LJ_COME!!!!! 阅读(140) 评论(0) 推荐(0)
摘要:贪心基础题。至少能赢多少次。换句话说,就是自己每次出一张牌,其他人尽量让你输,其他人足够聪明,当你出一张牌时,为了让你输,会出一张比你大的,除非其他人没有,那么这轮你就赢啦,为了不造成浪费,最优的方法肯定是出一张比你出的牌大的牌中最小的牌(贪心的思想),可以证明这样的贪心结构是正确的#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn=1001; int vis[maxn],a[maxn]; int n,m; int mai 阅读全文
posted @ 2012-11-27 17:29 LJ_COME!!!!! 阅读(132) 评论(0) 推荐(0)