POJ 1276 Cash Machine 解题报告
2009-02-05 23:31
429 查看
POJ 1276 Cash Machine 解题报告
编号:1276
考查点:枚举、搜索
思路:这个是zz让我看得代码,看了别人的自然知道如何抄了..自己肯定想不到怎么能够不拉下任何一种cash情况.。
提交情况:看了别人的代码,今天还在这道题上TLE了N次,后来才发现是循环变量写错了.汗.。
Source Code:
//POJ Grids 1276
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Bill{
int n;
int d;
};
Bill b[11];
bool flag[100001];
int compare(const void* e1,const void* e2)
{
Bill* a = (Bill*)e1;
Bill* b = (Bill*)e2;
return b->d - a->d;
}
int main()
{
int cash,n;
while (scanf("%d %d",&cash,&n)!=EOF)
{
for (int i=0;i<n;i++)
{
scanf("%d %d",&b[i].n,&b[i].d);
}
if (!cash||!n)
{
printf("0\n");
continue;
}
qsort(b,n,sizeof(Bill),compare);
memset(flag,false,sizeof flag);
flag[0] = true;
int max = 0;
for (int i=0;i<n;i++)
for (int j=max;j>=0;j--)
if (flag[j])
for (int k=1;k<=b[i].n;k++)
{
int temp = j + k*b[i].d;
if (temp>cash)
break;
max = temp>max ? temp : max;
if (!flag[temp])
flag[temp] = true;
}
printf("%d\n",max);
}
return 0;
}
总结:这道英文题不是书上的,自己目前肯定搞不定这么麻烦的问题,努力.。
By Ns517
Time 09.02.05
编号:1276
考查点:枚举、搜索
思路:这个是zz让我看得代码,看了别人的自然知道如何抄了..自己肯定想不到怎么能够不拉下任何一种cash情况.。
提交情况:看了别人的代码,今天还在这道题上TLE了N次,后来才发现是循环变量写错了.汗.。
Source Code:
//POJ Grids 1276
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Bill{
int n;
int d;
};
Bill b[11];
bool flag[100001];
int compare(const void* e1,const void* e2)
{
Bill* a = (Bill*)e1;
Bill* b = (Bill*)e2;
return b->d - a->d;
}
int main()
{
int cash,n;
while (scanf("%d %d",&cash,&n)!=EOF)
{
for (int i=0;i<n;i++)
{
scanf("%d %d",&b[i].n,&b[i].d);
}
if (!cash||!n)
{
printf("0\n");
continue;
}
qsort(b,n,sizeof(Bill),compare);
memset(flag,false,sizeof flag);
flag[0] = true;
int max = 0;
for (int i=0;i<n;i++)
for (int j=max;j>=0;j--)
if (flag[j])
for (int k=1;k<=b[i].n;k++)
{
int temp = j + k*b[i].d;
if (temp>cash)
break;
max = temp>max ? temp : max;
if (!flag[temp])
flag[temp] = true;
}
printf("%d\n",max);
}
return 0;
}
总结:这道英文题不是书上的,自己目前肯定搞不定这么麻烦的问题,努力.。
By Ns517
Time 09.02.05
相关文章推荐
- poj 1276 多重背包 解题报告
- poj解题报告——1276
- POJ 1276 解题报告
- POJ 3358 Period of an Infinite Binary Expansion 解题报告(欧拉函数+因式分解)
- 树状数组 离散化 求逆序数POJ 2299Ultra-QuickSort解题报告
- POJ 1006 Biorhythms 解题报告(中国剩余定理)
- POJ 2142 The Balance 解题报告(模线性方程)
- POJ 1002 487-3279 [解题报告] Java
- POJ1007解题报告
- PKU POJ 2524 解题报告(并查集)
- poj 3368 Frequent values解题报告【线段树】
- POJ 1001 解题报告 高精度大整数乘法模版
- poj_1664_放苹果_解题报告
- POJ 1157解题报告
- POJ 1002 解题报告
- POJ3673解题报告
- 置换的基础应用(附POJ 3270 Cow Sorting 解题报告)
- POJ 2248解题报告
- POJ3162 解题报告
- POJ 2491 Scavenger Hunt 解题报告 再次利用map判重