HDU 5778 abs (枚举)】的更多相关文章

abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive integer y≥2, that satisfy the following conditions: The absolute value of y - x is minimal To prime factors decomposition of Y, every element factor a…
abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Given a number x, ask positive integer y≥2, that satisfy the following conditions:1. The absolute value of y - x is minimal2. To prime facto…
http://acm.hdu.edu.cn/showproblem.php?pid=5778 这题的意思就是找离x最近的一个数y,且y是一个完全平方数,还是所有质因子都只能出现两次的完全平方数 一开始的思路是直接枚举这个差值,然后去两边找,val - res和val + res找,然后超时了. 其实也很正常,因为两个完全平方数的间隔实在太大了.中间有很多的数字, 那么把思路换一下, 题意是找a^2   <=  x  <=  b^2这样子的东西,那么可以同时开方,a <= sqrt(x)…
题意:给定一个数x,求正整数y≥2y\geq 2y≥2,使得满足以下条件: 1.y-x的绝对值最小 2.y的质因数分解式中每个质因数均恰好出现2次. 析:由于y质因数分解式中每个质因数均出现2次,那么y是一个完全平方数,设y=z*z,题目可转换成求z,使得每个质因数出现1次. 我们可以暴力枚举z,检查z是否符合要求, 显然当z是质数是符合要求,由素数定理可以得,z的枚举量在logn级别 复杂度 O(n4logn2\sqrt[4]{n}log\sqrt[2]{n}. 注意y>=2. 代码如下: #…
题意转化一下就是寻找一个数P,要求P质因素分解完后,质因素没有重复,还要保证abs(P*P-x)最小. 暴力,在sqrt(x)附近向下向上分别枚举一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vecto…
分析:y是一个无平方因子数的平方,所以可以从sqrt(x)向上向下枚举找到第一个无平方因子比较大小 大家可能觉得这样找过去暴力,但实际上无平方因子的分布式非常密集的,相关题目,可以参考 CDOJ:无平方因子数 http://acm.uestc.edu.cn/#/problem/show/618 这个题和CDOJ的题虽然不一样,但是可以从CDOJ发现这种数是很多的 官方题解:官方题解说这个无平方因子的枚举量在logn级别,可见非常小 #include <cstdio> #include <…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2489 思路:由于N, M的范围比较少,直接枚举所有的可能情况,然后求MST判断即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector> using namespac…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3118 思路:题目要求是去掉最少的边使得图中不存在路径长度为奇数的环,这个问题等价于在图中去掉若干条边,使得这个图成为二分图.注意到n不是很大,于是我们可以想到二进制枚举,枚举每条边的两个顶点是否在同一个集合中,若是,则删除这条边. #include<iostream> #include<cstdio> #include<cstring> #include<algori…
Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1876    Accepted Submission(s): 707 Problem Description Anton has a positive integer n, however, it quite looks like a mess, so he…
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑(i=0  n−1)  |A[i]−B[n−1−i]|The difference between the two characters is defined as the difference in ASCII.You should find the maximum length of two non-ov…