02 2014 档案
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1243d[i][j] 代表第i 个字符与第 j 个字符的最大的得分。,,最大公共子序列变形 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 2000+10; 8 9 char s[maxn], x[maxn], y[maxn];10 int f[3000], val[maxn], d[maxn][maxn];11 int main()12 {13 ...
阅读全文
摘要:题目:http://codeforces.com/contest/397/problem/B题意:给一个n ,求能不能在[l, r]的区间内的数字相加得到, 数字可多次重复。。比赛的时候没有想出来,看见这么大的数应该知道是思维题,比赛的时候还想会不会是背包什么的其实数据有10^9,逗了。。。。k*[l, r]的范围是[k*l, k*r]; 所以只需要求n是不是在 【k*l , k*r】的范围内就行了代码: 1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int t; 8 __int64 k...
阅读全文
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1559 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 1000+10; 8 const int INF = 1<<28; 9 int map[maxn][maxn]; //表示以[1,1]为左上角,以[i,j]为右下角的矩形的和10 11 int main()12 {13 int t, i, j, m, n, x, y;14 in...
阅读全文
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=1257虽然分类是dp感觉还是贪心比较水 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 1000+10; 8 int d[maxn]; //d数组存储一套系统的目前的发射的最小的高度 9 10 int main()11 {12 int n, i, x, cou, j;13 while(~scanf("%d", &n))14 ...
阅读全文
摘要:第一次做tc 的比赛,一点也不懂,虽然题目做出来了,但是,也没有在比赛的时候提交成功。。还有,感谢一宁对tc使用的讲解。。贴一下代码。。。。。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 cl...
阅读全文
摘要:题目:http://poj.org/problem?id=1191黑书116页的例题将方差公式化简之后就是 每一块和的平方 相加/n , 减去平均值的平方。可以看出来 方差只与 每一块的和的平方有关,所以就是求每个矩形的总分的平方和 尽量小。。。。 1 #include 2 #include 3...
阅读全文
摘要:题目:http://poj.org/problem?id=2777区间更新,比点更新多一点内容, 详见注释, 参考了一下别人的博客。。。。参考博客:http://www.2cto.com/kf/201402/277917.html 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 100000 + 10; 7 8 bool mark[35]; 9 struct node 10 { 11 int l, r, kind; 12 }tr[max...
阅读全文
摘要:题目:http://poj.org/problem?id=2886题意:N个孩子顺时针坐成一个圆圈且从1到N编号,每个孩子手中有一张标有非零整数的卡片。第K个孩子先出圈,如果他手中卡片上的数字A大于零,下一个出圈的是他左手边第A个孩子。否则,下一个出圈的是他右手边第(-A)个孩子。第p个出圈的孩子会得到F(p)个糖果,F(p)为p的因子数。求得到糖果数最多的是哪个孩子及得到多少糖果。跟上一个 约瑟夫环的题目很像,就是加了一个反素数。虽然我还是不太理解,但还是无耻的从别人的结题报告上把反素数表copy了下来。。。 1 #include 2 #include 3 #include 4 #in...
阅读全文
摘要:题目:http://poj.org/problem?id=2828题意:有n个人插队,给定插队的先后顺序和插在哪个位置还有每个人的val,求插队结束后队伍各位置的val。线段树里比较简单的题目了,点的更新。。思想是 从后向前插入,用num存储 每一段剩余的位置。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 200000 + 10; 8 int n, pos[maxn], val[maxn], ans[maxn]; 9 10 struct...
阅读全文
摘要:题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2351题意:xyez, xy表示一个十进制数,z表示xy后面有几个0,这些个人成一个约瑟夫环,隔一个人杀一个人。。求哪个位置上的人会幸存,用一般的方法...
阅读全文
摘要:题目:http://poj.org/problem?id=2528题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。现在往墙上贴N张海报,每张海报的宽度是任意的,但是必定是单位宽度的整数倍,且 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 10000+10; 7 int n, cnt; 8 int map[2*maxn][2], ans, f[2*maxn]; 9 struct node 10 { 11 int l, r, n; //n代表是哪种颜色...
阅读全文
摘要:题目:http://poj.org/problem?id=2352题意:给出n个星星的坐标, 每个星星的左下角有几个星星,该星星的level 就是几。求level为0~n-1的个数。本来想用线段树做,但是线段树还没理解好,做不出来, 就用树状数组做了。。。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 32010; 7 int c[maxn], lev[15010]; 8 9 void init()10 {11 for(int i = 1; i 0)...
阅读全文
摘要:题目:http://poj.org/problem?id=2492题意:跟上一道1703题差不做,给出m对昆虫交配,问 有没有同性恋。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 2010; 8 int bin[maxn], op[maxn], n; 9 void init()10 {11 for(int i = 1; i <= n; i++)12 {13 bin[i] = i;14 op...
阅读全文
摘要:题目:http://poj.org/problem?id=1703题意:一个地方有两个帮派, 每个罪犯只属于其中一个帮派,D 后输入的是两个人属于不同的帮派,A后询问 两个人是否属于 同一个帮派。用op[]数组记录 不跟自己在一个帮派中的一个人, 然后再输入不跟自己在一个帮派的人的时候,把这个人跟 ...
阅读全文
摘要:题目:http://poj.org/problem?id=3368题意:给定n个数,顺序为非下降,询问某个区间内的数出现最多的数的 出现次数。。大白书上的 例题。。算是RMQ变形了,对 原数组重新分段,并标记相同的个数为 该段的数值,然后RMQ... 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int maxn = 100005; 8 const int maxm = 30; 9 10 int d_max[maxn][maxm],a[maxn];11 int...
阅读全文
摘要:RMQ支持操作:Query(L, R): 计算Min{a[L],a[L+1], a[R]}。预处理时间是O(nlogn), 查询只需 O(1)。RMQ问题 用于求给定区间内的最大值/最小值问题。。询问的次数多的时候 好用。。这个题目我至少得开数组开到 80000才能过,不知道为什么。。刚开始还写错了,贡献了好多RE和WA..题目:http://poj.org/problem?id=3264题意:给n个数,q次询问,求最值的差。。 1 #include 2 #include 3 using namespace std; 4 const int maxn = 80000; 5 const in..
阅读全文
摘要:树状数组支持两种操作:Add(x, d)操作: 让a[x]增加d。Query(L,R): 计算 a[L]+a[L+1]……a[R]。当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一区间元素之和的时候,可以考虑使用树状数组.通常对一维数组最直接的算法可以在O(1)时间内完成一次修改,但是需要O(n)时间来进行一次查询.而树状数组的修改和查询均可在O(log(n))的时间内完成.在二维情况下:数组A[][]的树状数组定义为: C[x][y] = ∑ a[i][j], 其中, x-lowbit(x) + 1 2 #include 3 #include 4 #include 5 #...
阅读全文
摘要:题目:http://poj.org/problem?id=3321 题意: 苹果树上n个分叉,Q是询问,C是改变状态。。。。 开始的处理比较难,参考了一下大神的思路,构图成邻接表 并 用DFS编号 白书上一维树状数组模板: AC代码:
阅读全文
摘要:题目:http://poj.org/problem?id=2195有若干个人和若干个房子在一个给定网格中,每人走一个都要一定花费,每个房子只能容纳一人,现要求让所有人进入房子,且总花费最小。构造一个超级源s和超级汇t,超级源s与U中所有点相连,费用cost[s][u]=0(这是显然的),容量cap[...
阅读全文
摘要:题目:http://poj.org/problem?id=3694 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const int M...
阅读全文
摘要:题目:http://poj.org/problem?id=1459题意:有一些发电站,消耗用户和中间线路,求最大流。。加一个源点,再加一个汇点。。其实,过程还是不大理解。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const int INF=1q;16 memset(flow,0,sizeof(flow));17 f=0;18 while(1)19 {20 memset(a,0,sizeof(a));21 ...
阅读全文
摘要:题目:http://acm.hdu.edu.cn/showproblem.php?pid=3549模板题,白书上的代码。。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 const int INF=1q;16 memset(flow,0,sizeof(flow));17 f=0;18 while(1)19 {20 memset(a,0,sizeof(a));21 a[s]=INF;22 ...
阅读全文
摘要:题目:http://poj.org/problem?id=1364 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 const int INF=(1<<28); 8 int n,m,d[110];...
阅读全文
摘要:题目:http://poj.org/problem?id=2409题意:用k种不同的颜色给长度为n的项链染色网上大神的题解:1.旋转置换:一个有n个旋转置换,依次为旋转0,1,2,```n-1。对每一个旋转置换,它循环分解之后得到的循环因子个数为gcd(n,i).2.翻转置换:分奇偶讨论。奇数的时候...
阅读全文
posted @ 2014-02-10 23:30
水门
摘要:题目:http://poj.org/problem?id=3159题意:幼稚园分糖果,输入a,b,c表示,小孩a最多只能忍受小孩b的糖果比他多c个。求第一个小孩和最后一个小孩最多可以相差多少个糖果。卡队列,spfa用队列超时,就改成了栈 就A了。。以下两点题解是看了网上大神的。。。1、问题转换:题目...
阅读全文
摘要:题目:http://poj.org/problem?id=1201题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小。 1 #include 2 #include 3 #include 4 #include 5 #in...
阅读全文
摘要:题目:http://codeforces.com/contest/389/problem/C题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1;很简单的贪心,比赛的时候没想出来。、、、、、先从小到大排一下序,然后从最上层向下找,只要能承受住重量就行。而且因为已经排序了找的都是尽量小的。。。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 {10 int n,a[110],f[110],sum,x;11 int i,...
阅读全文

浙公网安备 33010602011771号