2014年3月2日

【HDOJ】1203 I NEED A OFFER!

摘要: DP问题。#include #define MAXNUM 10002int main() { int m, n; int cost[MAXNUM]; // the Cost for every school float prob[MAXNUM]; // the probality for every school float probs[MAXNUM]; // the probality for All-amount-money int i, j; while ( scanf("%d %d", &n, &m)!=EOF && (m||n)) 阅读全文

posted @ 2014-03-02 17:15 Bombe 阅读(145) 评论(0) 推荐(0) 编辑

【POJ】1692 Crossed Matchings

摘要: 经典DP,想了很久,开始想复杂了。#include using namespace std;#define MAXNUM 100int mymax(int a, int b) { return (a>b) ? a:b;}int main() { int case_n; int a_n, b_n; int i, j; int a[MAXNUM], b[MAXNUM]; int match[MAXNUM][MAXNUM]; int max_a2b[MAXNUM][MAXNUM], max_b2a[MAXNUM][MAXNUM]; cin >>case... 阅读全文

posted @ 2014-03-02 15:48 Bombe 阅读(266) 评论(0) 推荐(0) 编辑

2014年3月1日

【HDOJ】2037 今年暑假不AC

摘要: qsort排序后DP,水题。注意,数组开大点儿,把时间理解为0~23,开太小会wa。#include #include #define MAXNUM 100int comp(const void *a, const void *b) { return *(int *)a - *(int *)b;}int mymax(int a, int b) { return (a>b) ? a:b;}int main() { int time[MAXNUM][2], n; int i, j, end; int num[MAXNUM]; while (scanf("%d",... 阅读全文

posted @ 2014-03-01 23:01 Bombe 阅读(251) 评论(0) 推荐(0) 编辑

【HDOJ】1720 A+B coming

摘要: 水题。#include #include #define MAXNUM 1005int stoi(char);int main() { char sa[MAXNUM], sb[MAXNUM]; int a, b; int i; while (scanf("%s %s", sa, sb) != EOF) { a = 0; for (i=0; i='0' && ch='A' && ch='a' && ch<='f') return ch-'a'+ 阅读全文

posted @ 2014-03-01 22:12 Bombe 阅读(159) 评论(0) 推荐(0) 编辑

【POJ】1141 Brackets Sequence

摘要: 经典DP问题,注意输入不要使用while(xxx != EOF),否则WA,测试数据只有一组。同样的测试数据可能有多种答案。但最小长度唯一。一定不能用while,切记。#include using namespace std;#include #define MAXNUM 200#define MAXVAL 32767string match(char []);int main() { string regstr; char str[MAXNUM]; cin >>str; regstr = match(str); cout =0; i--) { fo... 阅读全文

posted @ 2014-03-01 10:40 Bombe 阅读(192) 评论(0) 推荐(0) 编辑

2014年2月28日

【HDOJ】1098 Ignatius's puzzle

摘要: 数学归纳法,得证只需求得使18+ka被64整除的a。且a不超过65。#include int main() { int i, j, k; while (scanf("%d", &k) != EOF) { j = 0; for (i=0; i<65; i++) { if ((18+k*i) % 65 == 0) { j = 1; break; } } if (j) printf("%d\n", i); ... 阅读全文

posted @ 2014-02-28 22:37 Bombe 阅读(169) 评论(0) 推荐(0) 编辑

【HDOJ】1076 An Easy Task

摘要: 水题,如题。#include #define chk(Y) (Y%4==0 && Y%100!=0) || Y%400==0int main() { int case_n; int i, y, n; scanf("%d", &case_n); while (case_n--) { scanf("%d %d", &y, &n); i = 0; while (1) { if ( chk(y) ) i++; if (i) { if ... 阅读全文

posted @ 2014-02-28 22:19 Bombe 阅读(139) 评论(0) 推荐(0) 编辑

【HDOJ】1196 Lowest Bit

摘要: 水题,原理是计算机组成原理中的负数的补码的求码。利用按位与可解。#include using namespace std;int main() { int n; while (1) { cin >> n; if (n == 0) break; cout <<(n&(-n))<<endl; } return 0;} 阅读全文

posted @ 2014-02-28 22:00 Bombe 阅读(113) 评论(0) 推荐(0) 编辑

【HDOJ】1197 Specialized Four-Digit Numbers

摘要: 水题,暴力可解。#include using namespace std;int chg(int n, int base);int main() { int i; int tmp; for (i=2992; i 0) { sum += n % base; n = n / base; } return sum;} 阅读全文

posted @ 2014-02-28 21:58 Bombe 阅读(163) 评论(0) 推荐(0) 编辑

【POJ】1505 Copying Books

摘要: 此题主要采用DP思路,难点是求解"/",需要考虑划分数量不够的情况,先采用DP求解最优解,然后采用贪心求解slash。防止中间结果出错,使用了unsigned int。#include using namespace std;#define MAXNUM 501unsigned int pages[MAXNUM][MAXNUM];int main() { int case_n, m, k; int i, j, p, q; unsigned min, tmp, sum; cin >>case_n; for (p=1; p>m>>k; for (i 阅读全文

posted @ 2014-02-28 16:27 Bombe 阅读(198) 评论(0) 推荐(0) 编辑

导航