随笔分类 -  周训练

摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2498题意:给定 一个 有向图 ,求出 从 图中只有 一个 入度为0 的点 s 和 一个 出度 为0 的 点 t 求 s 到t的 最长路径 若有 多条 输出 字典序最小的!题解:SPFA + 反向建图 。对于 所要求的路径 ,s 的下一个点 是 与 s相连 且 距离 t 最长的点 ,若有 多个 选择序号 最小的 。所以 自然 想到 求 各个点 到 t 的 最短距离 ,这样就 用到了 反向建图,并用 pre 记录的他的 前驱结点 1 #inclu 阅读全文
posted @ 2012-12-08 10:40 Szz 阅读(632) 评论(0) 推荐(0) 编辑
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497题意 : 给定一个 无向图 和 一个点 s 求 是否 图中的 所有环 都包含 点s (保证 图中 至少 有 一个环)题解 : dfs 求解 只要 搜到 一个 被访问过的点 而且这个点 不是 s 那么 就有环 不含有 sView Code 1#include<cstdio>2#include<cstring>3#include<cmath>4#include<iostream>5#includ 阅读全文
posted @ 2012-12-02 19:32 Szz 阅读(202) 评论(0) 推荐(0) 编辑
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2493好纠结 这么道 破题 比赛是竟然 没做出来 ,比赛 完后 加了个 条件就对了 ,为什么 比赛时 那么 没状态 。。。。。。。。。。。 题意:给出一个无向图 ,一个 原点 s 一个终点 t 求 一条 最短的路径 值 从 s 到 t ,对于 这条路径 可以 将 其中的 一条边的权值 减半。题解 : dij + 枚举 首先 我们可以 得到 知道 对于 t 来说 最小值 = min(与他 连接的点的 最小值 + w[i][t], s 到 i 的 阅读全文
posted @ 2012-12-02 18:08 Szz 阅读(234) 评论(0) 推荐(0) 编辑
摘要:这道题以前做过了 今天有做了一遍,发现比以前顺手多了,题意:给一个N*N的方阵,从[1,1]到[n,n]走K次,走过每个方格加上上面的数(每一个 方格只能向下 后向右走), 然后这个格上面的数变为0。求可取得的最大的值。题解:拆点 + 费用流 ;将 每一个点拆分成两个 , 为了 保证 只能算一次 流量为1 花费为 方格的值,有为了 保证 其他的路径 可以 从这个点 走过 再建一条 流量 为 inf 费用 为 0 的 边 1#include<cstdio>2#include<cstring>3#include<cmath>4#include<iostre 阅读全文
posted @ 2012-09-27 21:24 Szz 阅读(220) 评论(0) 推荐(0) 编辑
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4365题意:一个 n*n的 矩阵 ,有m个 格子,已经染色,有 k种颜色可以选 ,,对剩下的格子进行染色,使得 矩阵无论 反转 或者 旋转 90 度 多少次 都不变, 一开思做这道题是,找到了 规律,以为可以 用bool 类型 存 5000*5000 的数组,但每一次 ,都要初始划,带来了很大的时间消耗,直接 tle 。。。。。。其实 可以 有结构体 来存每次将 坐标 缩小在 左上角的 下三角 内,然后 排序 ,判断 有多少 不同的即可 规律:因为满足左右上下 左右对称 ,对角线对称,所以 我们 只要 算 . 阅读全文
posted @ 2012-08-15 17:34 Szz 阅读(285) 评论(0) 推荐(0) 编辑
摘要:#include<stdio.h>int ans,a[22],f,step;int judge(){ int i; for(i=1;i<=20;i++) if(a[i]==1)return 0; return 1;}void change(int x){ a[x]=!a[x]; if(x-1>=1)a[x-1]=!a[x-1]; if(x+1<=20)a[x+1]=!a[x+1];}void dfs(int x,int num){ if(step==num) { if(judge()) { ... 阅读全文
posted @ 2012-04-09 17:41 Szz 阅读(179) 评论(0) 推荐(0) 编辑
摘要:注意 标记hash[],不然会错(数据状态好像很多 ,所以要标记)http://poj.org/problem?id=3185#include<stdio.h>#include<string.h>#define N 1000000struct node{ int num; int step;}p[N];bool hash[1048576];int d[20]={0xC0000,0xE0000,0x70000,0x38000,0x1C000,0xE000,0x7000,0x3800,0x1C00, 0xE00,0x700,0x380,0x1C0,0xE0,0x... 阅读全文
posted @ 2012-04-08 21:59 Szz 阅读(251) 评论(0) 推荐(0) 编辑
摘要:http://poj.org/problem?id=3191此题的解法基于以下几点:(1) 如果一个数是奇数,那么它的二进制形式的最后一位肯定是1,我们可以去掉此 1,就是(x-1)/-2,进入(2)(2) 如果一个数的最后一位为 0 ,我们可以把这个数右移(可以类比以 2 为基的二进制数的操作)一位,然后它的二进制的倒数第二个数就成了最后一个,就是 x=x/-2,然后进入(1)迭代,直到变为 0#include<stdio.h>#include<math.h>int a[40];int main(){ int n,i; while(scanf("%d&quo 阅读全文
posted @ 2012-04-07 17:46 Szz 阅读(305) 评论(0) 推荐(0) 编辑
摘要:/*http://acm.hdu.edu.cn/showproblem.php?pid=4039题意:给出N对好友关系,之后Q次提问,问可以对该用户推荐的相识度最高的好友;推荐好友满足的条件:该用户的所有好友的好友中,出现次数最多的,而且推荐好友本身不是该用户的好友;若有多个推荐好友时,按字典序输出;一道悲剧的题啊*/#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 2500#include<iostream>#include<algorithm>using 阅读全文
posted @ 2012-04-06 20:52 Szz 阅读(313) 评论(0) 推荐(0) 编辑
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4033思路:二分 先找 两边之和的最小max 和两边只差的最大 min 则边的长度 L 必然 min<l<max 然后二分求解 注意啊,一开始定义 eps 是为e-6,wa 改为e-8 ac #include<stdio.h>#define N 1000#include<math.h>#define eps 1e-8const double pi=2*acos(-1);double a[N];int main(){ int T,l,i,n; scanf("%d&q 阅读全文
posted @ 2012-04-05 20:43 Szz 阅读(171) 评论(0) 推荐(0) 编辑
摘要:1http://acm.hdu.edu.cn/showproblem.php?pid=4034 vis[][]作用是 防止一条边被删多次 2 3 #include<stdio.h> 4 #include<string.h> 5 #define N 1000 6 int ans; 7 int map[N][N],n,f,vis[N][N]; 8 void search() 9 {10 int i,j,k;11 memset(vis,0,sizeof(vis));12 for(k=1;k<=n;k++)13 {14 for(i=1;i<=n;i+... 阅读全文
posted @ 2012-04-05 19:29 Szz 阅读(162) 评论(0) 推荐(0) 编辑
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1849/*思路 : 优先队列 bfs ,从每一天中 病毒类型最小的开始 ,所以优先队列 先 按天 排在按类型 */#include<iostream>#include<stdio.h>#include<queue>#include<cmath>#include<string.h>#define N 600using namespace std;struct node{ int x; int y; int day; i 阅读全文
posted @ 2012-04-01 21:01 Szz 阅读(122) 评论(0) 推荐(0) 编辑
摘要:http://poj.org/problem?id=2939题意:某个人点到两次时这个人自杀,当某个人点到三次时,循环结束,求结束时剩余的人数;#include<stdio.h>#define inf 1000009struct node{ __int64 q; int num; int next;}p[inf];int link[inf],m;void init(){ for(int i=0;i<=inf;i++) { link[i]=0; } m=1;}int find(__int64 q,int x){ int i;... 阅读全文
posted @ 2012-03-28 20:15 Szz 阅读(194) 评论(0) 推荐(0) 编辑
摘要:1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 string str[]={"00", "02","04","06","30","32","34","36","40","42" 5 ,"44","46","50","52& 阅读全文
posted @ 2012-03-21 08:52 Szz 阅读(200) 评论(0) 推荐(0) 编辑
摘要:#include<stdio.h>int f[30005];int find(int x){ if(x!=f[x])f[x]=find(f[x]); return f[x];}int main(){ int n,m,i,j,k,a,b; while(scanf("%d%d",&n,&m),m+n) { for(i=0;i<=n;i++)f[i]=i; for(i=1;i<=m;i++) { scanf("%d",&k); scanf("%d",&a); in... 阅读全文
posted @ 2012-03-15 20:59 Szz 阅读(145) 评论(0) 推荐(0) 编辑
摘要:#include<stdio.h>#include<string.h>const int N=100;int n,m,next[N];char dna[N][N];void get_next(char *str,int len){ next[0]=-1; int j=0,k=-1;//k记录next[]; while(j<len) { if(k==-1||str[j]==str[k]) { k++; j++; if(str[k]!=str[j]) ... 阅读全文
posted @ 2012-03-15 20:02 Szz 阅读(162) 评论(0) 推荐(0) 编辑
摘要:PKU 3370 Halloween treats 【鸽笼定理】分类: 数论 2010-08-20 19:21 127人阅读 评论(0) 收藏 举报【题目地址】http://acm.pku.edu.cn/JudgeOnline/problem?id=3370【题目大意】 万圣节邻居i会发给孩子们一定数量的糖果a[i],现在有c个孩子和n户邻居(1<=c<=n<=100000), 为了不引起纠纷,孩子们决定选择性的去某些邻居家索要糖果,使得到的糖果总数可以均分给n个人(只要均分就行,不要求糖果数最多)。【解题思路】 基本原理:如果n+1个物体放进n个盒子,那么至少有一个盒子包含 阅读全文
posted @ 2012-03-14 17:46 Szz 阅读(415) 评论(0) 推荐(0) 编辑
摘要:Annoying painting toolTime Limit: 1000MS Memory limit: 65536K题目描述Maybe you wonder what an annoying painting tool is? First of all, the painting tool we speak of supports only black and white. Therefore, a picture consists of a rectangular area of pixels, which are either black or white. Second, ther 阅读全文
posted @ 2012-03-12 21:00 Szz 阅读(216) 评论(0) 推荐(0) 编辑
摘要:找差异为一个字符的串http://poj.org/problem?id=1035#include<iostream>#include<string>#include<string.h>#include<stdlib.h>#include<stdio.h>#define N 10005using namespace std;string str[N];int num,l,b[N];int replace(string c,string b){ int i,sum=0; for(i=0;i<c.length();i++) { if( 阅读全文
posted @ 2012-03-09 21:55 Szz 阅读(163) 评论(0) 推荐(0) 编辑
摘要:马虎了一下,少些了个=号,错了N 遍http://poj.org/problem?id=3020#include<stdio.h>#include<string.h>#define N 1000int a,h,w;char str[N][N];int map[N][N],vis[N],result[N];int bian(int x,int y){ if(x>=0&&x<=h&&y>=0&&y<=w) { if(str[x][y]=='*') { return x*w+y; } re 阅读全文
posted @ 2012-03-07 20:08 Szz 阅读(131) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示