NOI:7621 硬币面值组合

题目链接:http://noi.openjudge.cn/ch0201/7621/

NOI:7621 硬币面值组合_第1张图片

NOI:7621 硬币面值组合_第2张图片

题解:简单枚举

注意:排序;

         格式化输出 printf("%03d",i);格式化3位,不足补0

#include 
#include 
#include 
#include 
#include 
using namespace std;
int n;
struct point {
    int a,b,c;
};
bool compare(point a,point b)
{
    if(a.c!=b.c)return a.c>n;
    point all[10000];
    int size=0;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(i+j*2>n)break;
            else{
                if((n-i-j*2)%5==0){
                    point tmp;
                    tmp.a=i;
                    tmp.b=j;
                    tmp.c=(n-i-j*2)/5;
                    all[size++]=tmp;
                }
            }
        }
    }
    sort(all,all+size,compare);
    for(int i=0;iprintf("%03d",i+1);//格式化输出
        printf("%12d%12d%12d",all[i].a,all[i].b,all[i].c);
        cout<

你可能感兴趣的:(NOI)