贪心入门

来源:互联网 发布:葛根饮料销售网络方案 编辑:程序博客网 时间:2024/05/16 04:02

一、硬币问题(常规思维)

一、http://poj.org/problem?id=3085

二、区间问题

二、http://10.1.5.12/JudgeOnline/problem.php?id=1412

三、最小字典序

三、http://poj.org/problem?id=3617

#include<stdio.h>#include<queue>#include<string.h>#include<stdio.h>#include<queue>#include<string.h>#include<math.h>#include<algorithm>using namespace std;char data[2005];int main(){    int n;scanf("%d",&n);        int l,r,i,j,k=0;        for(int t=0;t<n;t++) {getchar();scanf("%c",&data[t]);}        l=0,r=n-1;        while(l<=r){            i=l,j=r;            while(i<=j&&data[i]==data[j]) i++,j--;            k++;            if(data[i]<data[j]) printf("%c",data[l++]);            else printf("%c",data[r--]);            if(k%80==0) printf("\n");        }if(k%80) printf("\n");        return 0;}
四、其它简单题


0 0