摘要: #include <stdio.h>#define MAXN 21int map[MAXN][MAXN];int startx, starty;int w, h, ok, minMove;int dr[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};int legal(int x, int y){ if(x >= 1 && y >= 1 && x <= h && y <= w ) return 1; return 0;}void in(){ int i, j; for(i = 1; i 阅读全文
posted @ 2011-04-20 23:08 L.. 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 要求求出一串数列中不重合的两段子序列的和的最大值思路:正着求一遍最大子串和,记录在lmax数组中,再倒着求一遍最大子串和,记录在rmax中,这时求出的是包含a[i]的最大和lmax[i],rmax[i],还要将lmax,rmax更新成其区间内的最大和,并不一定包括i,最后求出lmax[i] + rmax[i + 1]的最大值#include <stdio.h>int lmax[50000],rmax[50000],max;int main(){ int cas,n,a[50000],i,j; scanf("%d",&cas); while( cas-- 阅读全文
posted @ 2011-04-20 22:50 L.. 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 做出来要不要这么有感觉啊...以下转自http://hi.baidu.com/%8E%E1%D0%B3/blog/item/2f1d8f4c176a8dc4d1c86af9.html不过他写错了一个改过来了由于深度一定(m),所以使用深度优先搜索,自上而下的设定蛋糕序号,最顶层的为第1层,……,最底层的蛋糕为第m层,很明显满足题目条件的前i层的(从顶层(也就是编号为1的层)开始计数)最小面积mins[i]和体积minv[i]是在该层的半径以及高度都为i时取得,如果采用一般的神搜肯定会超时,所以这题还需要剪枝,剪枝条件有(从m层向上搜,假设前dep层的体积为sumv,面积为sums,当前所得的最 阅读全文
posted @ 2011-04-20 21:19 L.. 阅读(488) 评论(0) 推荐(0) 编辑
摘要: 明显的贪心#include <stdio.h>#include <iostream>#include <vector>#include <algorithm>using namespace std;struct BaoBei{ int p, m; double val;};bool cmp(const BaoBei &a, const BaoBei &b){ return a.p > b.p; // >号 降序排序}int main(){ int v, n; vector<BaoBei> vec; whil 阅读全文
posted @ 2011-04-20 17:46 L.. 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 可以测试自己的代码用时啦printf("used time = %.3lf\n",(double)clock()/CLOCKS_PER_SEC); 阅读全文
posted @ 2011-04-20 12:12 L.. 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 名称: sscanf() -从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( stringstr, string fmt, mixed var1, mixed var2 ... ); intscanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用于输入的,只是后者以屏幕(stdin)为输入源,前者以固定字符串为输入源。 其中的format可以是一个或多个{%[*] [width] [{h | l | I64 |L}]type | ' ' | '\t' | &# 阅读全文
posted @ 2011-04-20 11:51 L.. 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1.如果没有重合,总时间为102.影响搬运时间的是两个区间的重合,每次重合时间加103.从整体上看,每10分钟选择全部不冲突的区间搬运,程序上用一个cover数组记录区间被覆盖的次数,最后比较最大值,得到最大时间#include <iostream>#include <string.h>using namespace std;int main(){ int t; int cover[200]; cin >> t; while( t-- ){ memset(cover, 0,sizeof(cover)); int n, s, f; cin >> n 阅读全文
posted @ 2011-04-20 03:43 L.. 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 很CHUO的代码用的是单调队列还有更好的做法 以后补上#include <stdio.h>struct Queue{ int idx, val;}que[1000000];int a[1000000];int head, tail;int main(){ int n, k; scanf("%d%d",&n, &k); for(int i = 0; i < n; ++i){ scanf("%d",&a[i]); } // k 为1时候的特殊情况, 还有更好的做法.. if( k == 1 ){ for(int i 阅读全文
posted @ 2011-04-20 02:32 L.. 阅读(139) 评论(0) 推荐(0) 编辑