Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she'…
2013-09-18 08:13 //By BLADEVIL var n, m :longint; pre, other :..] of longint; last :..] of longint; flag :..] of boolean; tot :longint; ans :..] of longint; i :longint; l :longint; procedure connect(x,y:longint); begin inc(l); pre[l]:=last[x]; last[x…
2013-09-18 08:23 打表找规律 w[i]:=w[i-1];  奇 w[i]:=w[i-1]+w[i div 2];     偶 //By BLADEVIL var w :..] of longint; i :longint; n :longint; begin assign(input,'sumset.in'); reset(input); assign(output,'sumset.out'); rewrite(output); read(n); w[]:=; to n do =…
2013-09-18 08:12 由题可知,ans=∑i  ∑j(x[i]-x[j]) 最后整理完之后应该是不同系数的X[i]相加,所以这道题就成了求不同x[i]的系数 对于X[i],它需要减前面(i-1)个不同的数,所以系数先是(i-1),而计算它前 面的每个数时都需要被X[i]减,所以系数成了2*(i-1),而且X[i]会被后面(n-i) 个数减,且计算后面的x时,都会减x[i],所以需要减2*(n-i)所以系数就变成了 2*(2*i-n-1),累加每个即可 //By BLADEVIL va…
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6055   Accepted: 2610   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk ac…
Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 223064-bit integer IO format: %lld      Java class name: Main   Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to wa…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5258   Accepted: 2206   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6336   Accepted: 2743   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8800   Accepted: 3832   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoer…
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she's done. If s…
题目链接:http://poj.org/problem?id=2230 题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径. 解题思路:其实就是输出有向图的欧拉路,只是让你以点的形式输出.建图的时候,输入a,b直接建立(a,b)和(b,a)正反两条边,然后dfs递归遍历即可.注意输出点的位置:在边遍历完之后输出,原理暂时还没搞懂. 代码: #include<iostream> #include<cstdio> #include…
Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8109   Accepted: 3551   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers a…
[题目链接] http://poj.org/problem?id=2230 [算法] 欧拉回路 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #inclu…
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she's done. If s…
关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该不唯一. #include<cstdio> #include<cstring> #include<vector> #include<stack> #include<algorithm> #define rep(i,a,b) for(int i=a;i…
题目 题目链接,我只在poj上找到了题目,usaco居然上不去. 大意就是说有一些\(1\times 1\times 1\)的小方块堆在一起,问最多能装多少水. 我们在一次测试中出了这题,由于我写水题的能力太弱,挂掉了. 算法1 这是我当时想到的方法. 我们可以统计出每一层能装多少水.由于层数达到了\(10^9\),所以需要离散化一下. 我们可以用并查集来维护装水的面积. 时间复杂度:\(O(n^2 \alpha (n^2))\). 算法2 这是<算法艺术>\(P89\)上的例题(同时也是PO…
题目大意: 一共有N (1 ≤ N ≤ 1,000)个电线杆,有P P (1 ≤ P ≤ 10,000)对电线杆是可以连接的, 用几条线连接在一起的电线杆之间都可相互通信,现在想要使得电线杆1和电线杆N能相互通信, 并且电线公司提出KK (0 ≤ K < N)条电线是可以免费使用的, 当使用电线的数量超过K条,超出的电线要收费, 收的总费用为去掉免费使用的K条电线之后最长的那条电线的长度. 问最少费用是多少 Input * Line 1: Three space-separated intege…
题目大意: 输入n,k :n次操作 找到覆盖次数在k及以上的段的总长 一开始位置在0 左右活动范围为1-1000000000 接下来n行描述每次操作的步数和方向 Sample Input 6 22 R6 L1 R8 L1 R2 R Sample Output 6 下面的方法用了 map 和 区间表示法 http://www.cnblogs.com/zquzjx/p/8321466.html(区间表示法看这里) 但是不同于 题解 https://www.luogu.org/problemnew/s…
link:http://www.usaco.org/index.php?page=dec17results Problem A(Bronze) 这是一道非常简单的判断重叠面积的题目,但第一次提交仍会出错,实不应该 判断的关键在于矩形A的上界要大于B的下界,且A的下界要小于B的上界,则包含了相重叠的所有情况 同时,在数据范围较小时,也可使用染色法 #include <bits/stdc++.h> using namespace std; typedef long long ll; ],xy[],…
分析: 基础的欧拉路算法,变化在于要求每条边正向和反向各走一遍. 链式前向星构图,只要标记走过的单向边,边找边输出即可. code #include <iostream> #include <cstdio> using namespace std; struct node { int v, ne; } edge[100009]; int head[10009], vis[100009], cnt = 1; int n, m, x, y; void addedge (int u, i…
题目链接 : poj2230 大致题意: 有一个人每晚要检查牛场,牛场内有m条路,他担心会有遗漏,就每条路检查两次,且每次的方向不同,要求你打印他行走的路径(必须从1开始),打印一条即可. 思路分析 输入n条边,要求每条边都要走两次,每次的方向不同.那么就可以看成是有向图,把一条边分成两条边,就可以直接打印结果.但是这题还有一个陷阱,m最大为50000,n最大为10000,如果直接采用邻接矩阵数组放不下,那么我的方法就是利用一个动态数组存储结构体. struct node { int key;…
题意: Bessie 最近做了农场看守,他每天晚上的工作就是巡视农场并且保证没有坏人破坏农场.从谷仓出发去巡视,并且最终回到谷仓. Bessie 视力不是很好,不能像其他农场的看守一样,对农场的每一条连接不同场地的路走一遍就可以发现是不是有异常情况,他需要每条路都走两遍,并且这两边必须是不同的方向,因为他觉得自己应该不会两次都忽略农场中的异常情况. 每块地之间一定会由至少一条路相连.现在的任务就是帮他制定巡视路线.前提假设一定存在满足题意的路径. 输入: 第一行输入两个数N(2 <= N <=…
题目:http://poj.org/problem?id=2513 参考博客:http://blog.csdn.net/lyy289065406/article/details/6647445 http://www.cnblogs.com/LK1994/p/3263462.html #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stac…
题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有首字母指向尾字母的有向边,每个字母看成一个点,题中要求等效于判断图中是否存在一条路径经过每一条一次且仅一次,就是有向欧拉通路.统计个顶点的出入度,如果每个点的出入度都相同,那就是欧拉回路,如果有两个奇数度,那就是欧拉通路,除此之外,都不能满足要求.还有别忘了判断是否连通,此时用到并查集,图中所有的边…
欧拉回路第一题TVT 本题的一个小技巧在于: [建立一个存放点与边关系的邻接矩阵] 1.先判断是否存在欧拉路径 无向图: 欧拉回路:连通 + 所有定点的度为偶数 欧拉路径:连通 + 除源点和终点外都为偶数 有向图: 欧拉回路:连通 + 所有点的入度 == 出度 欧拉路径:连通 + 源点 出度-入度=1 && 终点 入度 - 出度 = 1 && 其余点 入度 == 出度: 2.求欧拉路径 : step 1:选取起点(如果是点的度数全为偶数任意点为S如果有两个点的度数位奇数取一…
poj 2229 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 21281   Accepted: 8281 Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an…
Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer…
Description Farmer John commanded his cows to search . Here are the possible sets of numbers that sum to : ) ++++++ ) +++++ ) ++++ ) +++ ) +++ ) ++ Help FJ count all possible representations <= N <= ,,). Input A single line with a single integer, N.…
Sumsets Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that sum to 7: 1) 1+1+1+1+1+1+1 2)…