赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2012年4月15日

摘要: 1. 用dfs,[A][B][C]为三个状态,且只有6个操作,a倒b,a倒c,b倒a,b倒c,c倒a,c倒b。知道用深搜了,但是还是不知道怎么写,看了别人的代码,才会写dfs()这个函数了。其实确定深搜了之后,写这个函数的时候,不需要考虑递归是怎么进行的,只需要考虑这次和下一次的操作过程即可。2. 以下是代码:/* ID: dollar4 PROG: milk3 LANG: C++ */ #include #include #include #include #include using namespace std; int a, b, c, p = 0, isin[20]; in... 阅读全文
posted @ 2012-04-15 14:42 赵乐ACM 阅读(210) 评论(0) 推荐(0) 编辑

2012年4月14日

摘要: 1. 枚举可以算出来,但是肯定超时,所以要剪枝,以等差数列a+nb说明;2. 几个可以剪枝的地方:b的范围是从1~2*m*m/(n-1); a的范围是0~2*m*m - (n-1) * b然后循环判断是不是pq了剪枝不是很充分,但是最慢3秒多给过了,哈哈3.以下是代码:/* ID: dollar4 PROG: ariprog LANG: C++ */ #include #include #include #include #include using namespace std; int main() { ofstream fout ("ariprog.out"); ... 阅读全文
posted @ 2012-04-14 23:04 赵乐ACM 阅读(383) 评论(0) 推荐(0) 编辑

2012年4月13日

摘要: 1. 这道题有好多种解法,看NOCOW,用枚举,DFS,BFS都能求解。我看到这个题的时候,连最基本的枚举怎么做都想不出来,差距呐。。。;2. 我挑选了解题报告中代码最短的读懂然后写出来了:/* ID: dollar4 PROG: clocks LANG: C++ */ #include #include #include #include #include #include #include using namespace std; #define FOR(x) for (c[x] = 0; c[x] > temp; a[i] = temp / 3 % 4; ... 阅读全文
posted @ 2012-04-13 21:56 赵乐ACM 阅读(242) 评论(0) 推荐(0) 编辑

摘要: 1.因为只有4个方块,所以枚举每个方块的选择顺序和放置方向(横放还是纵放),放置方式只有题目给出的6中基本模式,分别算出不同模式下最小的面积,更新最优解。第4、5个在本质上其实是一样。如图,不同模式对应的最小面积如下:设w1,w2,w3,w4表示4个方块的横长,h1,h2,h3,h4表示4个方块的纵长。w,h表示最小。1:w=w1+w2+w3+w4;h=max(h1,h2,h3,h4)2:w=max(w1+w2+w3,w4);h=max(h1,h2,h3)+h43:w=max(w1+w2,w3)+w4;h=max(h1+h3,h2+h3,h4)4:w=w1+w2+max(w3,w4);h=ma 阅读全文
posted @ 2012-04-13 16:19 赵乐ACM 阅读(131) 评论(0) 推荐(0) 编辑

2012年4月11日

摘要: 1. 枚举,注意里边的几个剪枝,标在代码中了2. 我的代码:/* ID: dollar4 PROG: crypt1 LANG: C++ */ #include #include #include #include #include using namespace std; int num[10], n; bool cmp(int a, int b) { return a > n; int i, j, k, l, m, s1, s2, s3, s4, s5; int cnt = 0, mm, nn, mn; for (i = 0; i > num[i]... 阅读全文
posted @ 2012-04-11 23:42 赵乐ACM 阅读(135) 评论(0) 推荐(0) 编辑

摘要: 1. 输入带回车符,空格,标点符号的字符串:while (fin >> temp) { str += temp; str += " "; } unsigned int len = str.size(); str.resize(len - 1);2. 判断是不是回文3. 以下是代码:/* ID: dollar41 PROG: calfflac LANG: C++ */ #include #include #include #define maxn 20010 using namespace std; char str1[maxn],str2[max... 阅读全文
posted @ 2012-04-11 22:34 赵乐ACM 阅读(135) 评论(0) 推荐(0) 编辑

摘要: 1. 这道题想多了,想得很复杂,其实就是把输入的一排数按照从小到大的顺序排列,然后得到相邻两个数之间的差,按从大到小的顺序排序,用这个数组所有元素的和减去前m-1个数,然后再加上m,就得到结果2. 以下是我的代码:/* ID: dollar4 PROG: barn1 LANG: C++ */ #include #include #include #include #include using namespace std; bool cmp1(int a, int b) { return a > b; } bool cmp2(int a, int b) { retur... 阅读全文
posted @ 2012-04-11 16:26 赵乐ACM 阅读(139) 评论(0) 推荐(0) 编辑

摘要: 1. 贪心,其他没啥说的2. 我的代码:/* ID: dollar4 PROG: milk LANG: C++ */ #include #include #include #include #include using namespace std; struct Node { int price; int num; } node[5000]; bool cmp(Node a, Node b) { return a.price > n >> m; for (i = 0; i > node[i].price >> node[i].num; sor... 阅读全文
posted @ 2012-04-11 10:25 赵乐ACM 阅读(148) 评论(0) 推荐(0) 编辑

摘要: 1. 直接用了上道题的函数,另外,进制转换:string trans(int a) { string str1 = ""; int tmp; while (a) { tmp = a % base; if (tmp #include #include #include #include using namespace std; int n, s; bool checkp(string str) { int len = str.size(); for (int i = 0; i > n >> s; ... 阅读全文
posted @ 2012-04-11 10:17 赵乐ACM 阅读(149) 评论(0) 推荐(0) 编辑

2012年4月9日

摘要: 1. 进制转换+回文判断+int与char之间相互转换;以下是代码:/* ID: dollar4 PROG: palsquare LANG: C++ */ #include #include #include #include #include using namespace std; int base; bool checkp(string str) { int len = str.size(); for (int i = 0; i > base; for (i = 1; i #include #include #include #include ... 阅读全文
posted @ 2012-04-09 19:37 赵乐ACM 阅读(144) 评论(0) 推荐(0) 编辑