HDU 5224 Tom and paper(最小周长)】的更多相关文章

HDU 5224 Tom and paper(最小周长) Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know th…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper. Input I…
Tom and paper Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Description Tom面前有一张纸,它的长和宽都是整数.Tom知道这张纸的面积n,他想知道这张纸的周长最小是多少.A的某一段完全重合,或者能够经过上下左右平移与折线A的某一段完全重合,则表示秋实大哥吹出了妹子的一部分旋律. Input 有多组数据.第一行一个正整数T,表示数据组数.接下来…
Tom and paper Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.                         Input In the first line, there is a…
1283 最小周长 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值.例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为20. Input 输入1个数S(1 <= S <= 10^9). Output 输出最小周长.一开始直接遍历超时,由数学定理,周长一定正方形面积最大…
题目链接:hdu 5225 Tom and permutation #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 100; const int mod = 1e9+7; int N, ans, V[maxn + 5], A[maxn + 5]; ll S[maxn + 5], L[m…
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1967 Accepted Submission(s): 442 Special Judge Problem Description The Wall has down and the King in the north has to sen…
1283 最小周长 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值.例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为20. Input 输入1个数S(1 <= S <= 10^9). Output 输出最小周长. Input示例 24 Output示例 20 [分析…
一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值.例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为20. Input 输入1个数S(1 <= S <= 10^9). Output 输出最小周长. Input示例 24 Output示例 20水题.. #include <algorithm> #include <iostream> #include <cstring…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5224 题意: 给出矩形的面积,求出最小的周长. 样例: Sample Input 3 2 7 12   Sample Output 6 16 14 思路: 这个题只需要注意时间就可以了.   刚开始就就是直接从1开始循环找出满足条件的后比较,结果超时了.... 后来又开始从n/2开始查找,这个不需要比较只要找到满足条件就可以了可是还是超时了.... 最后是从sqrt()开始才过的. #include…
Description There is a piece of paper in front of Tom, its length and width are integer. Tom knows the area of this paper, he wants to know the minimum perimeter of this paper.   Input In the first line, there is an integer T indicates the number of…
Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others) Total Submission(s): 1879    Accepted Submission(s): 938 Problem Description There are N cities in our country, and M one-way roads connecting them. Now L…
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可以监控到所有小偷. 思路:求最小割可以转化为最大流.每个城市之间拆点,流量是sa[i],再增加一个超级源点S和s相连,增加一个超级汇点T,让d的第二个点和T相连.然后就可以做了. #include <cstdio> #include <algorithm> #include <i…
Tom and matrix Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analyse: 直接可以用Lucas定理+快速幂水过的,但是我却作死的用了另一种方法. 方法一:Lucas定理+快速幂水过 方法二:首先问题可以转化为求(0,0),(n,m)这个子矩阵的所有数之和.画个图容易得到一个做法,对于n<=m,答案就是2^0+2^1+...+2^m=2^(m+1)-1,对于n>m…
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7469   Accepted: 4451 Description Consider a town where all the streets are one-way and each street leads from one intersection to an…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个模式完成. 两个机器初始都是0模式,一个机器转换一个模式需要重启一次.问你最少需要重启几次能完成所有的任务. 不太明显的二分匹配,将每个任务的两个模式连线,大概就能看出来这是个最小点覆盖问题. /* 将下面任务的a状态和b状态连边,线的个数就是任务个数. 要使重启次数最少,那么就要使选择的点最少而且…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y轴一次.每次加起来的无非都是新加的边(flag为1)或者是新减的边(flag为-1),即加起来的是此时的总长度(T[1].val)减去上一次扫到的总长度(last)的绝对值(T[1].val - last).(注意用c++提交,g++会wa) #include <iostream> #includ…
题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include &l…
Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997    Accepted Submission(s): 306 Problem Description The empire is under attack again. The general of empire is planning to defend his…
HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4个方向都加完就是答案 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 5005; int n; struct Rec { int…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少派多少人去 思路: 转化题意,求用最少的有向边覆盖点        -------->      最小边覆盖数目=顶点数-最大二分匹配数目 注意:这道题目中说得是有向无环的DAG,所以顶点数目不能按照2倍来计算 在DAG中我们假设点集为 -----> Ni     然后建立每个点对应的虚点 ---…
Problem Description CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, without any surprise, there are only 99.9 yuan left. he is too distressed and thinking about how to tide over the last days. Bein…
http://acm.hdu.edu.cn/showproblem.php?pid=3488 给一个无源汇的,带有边权的有向图 让你找出一个最小的哈密顿回路 可以用KM算法写,但是费用流也行 思路 1. 哈密顿回路对于每个点的流量有限制,因此$V$拆开为$V$和$V'$ 2. 我们建立附加源点$S$和附加汇点$T$哈密顿回路中的每个点有其唯一的后继和前驱,换句话说,对于任意一个点$V$,它满足$in(V)=out(V)$ 为了满足该条件,从源点向$V$ 连接容量为1,费用为0的边,从$V'$向汇…
http://acm.hdu.edu.cn/showproblem.php?pid=3526 题意:有个屌丝要配置电脑,现在有n个配件需要购买,有两家公司出售这n个配件,还有m个条件是如果配件x和配件y在不同公司买的话,需要花费额外的w元.现在需要计算购买这n个配件的最小花费. 思路: 一开始想的费用流,但好像不太行?? 其实一看到二选一的话就首先应该往最小割和二分图这个方向去想一想的. 这题用最小割来做,对于这m条件,在这两个顶点之间加两条有向边. #include<iostream> #i…
Give out candies Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 218    Accepted Submission(s): 66 Problem Description There are n children numbered 1 to n, and HazelFan's task is to give out…
http://acm.hdu.edu.cn/showproblem.php?pid=5067 贴题解 由于Harry的dig machine是无限大的,而装载石头和卸载石头是不费时间的,所以问题可以转化成:从某一点出发,遍历网格上的一些点,每个点至少访问一次需要的最小时间是多少.这就是经典的旅行商问题,考虑到我们必须要遍历的点只有不到10个,可以用状态压缩解决. Dp[i][j]表示i状态的点被访问过了,当前停留在点j 需要的最少时间.枚举另一点不在i状态内的点k,从点j节点走向点k,状态转移…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这样得到最大流 maxflow / (E + 1) ,最少割边数 maxflow % (E + 1) 道理很简单,如果原先两类割边都是最小割,那么求出的最大流相等 但边权变换后只有边数小的才是最小割了 乘(E+1)是为了保证边数叠加后依然是余数,不至于影响求最小割的结果 因为假设最小割=k,那么现在新…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因为树可以奇偶分层,从而根据二分图染色的原理可以确定树是二分图.我们可以用染色法确定出两个集合求最大匹配,也可以将边补成双向的,然后将最大匹配/2. 代码: #include<iostream> #include<cstdio> #include<cstring> #incl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3360 题目大意: 在一个n*m的格子中,每个格子有一个数值,-1表示空,其余表示财宝.每个财宝的数值转换成二进制数, 12个二进制位上数值,从右到左,第i个位是1表示图上相应第i序号位置需要有警卫.所有的要求位置有警卫财宝才安全. 财宝可以被警卫替换.问至少需要替换多少财宝才能保证所有财宝的安全. 解题思路: 需要警戒位置是财宝的讯号对财宝位置讯号建边.由于警戒位置与财宝位置的横纵坐标奇偶相反,可以…
Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2350    Accepted Submission(s): 1241 Problem Description Yifenfei very like play a number game in the n*n Matrix. A positive integer number…