hdoj 4143 A Simple Problem
2013-10-10 21:22
204 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4143
解题思路:枚举 n=a*b, a<b. 则有 若a,b 奇偶性相同,则 x=(b-a)/2. 不断更新~
解题思路:枚举 n=a*b, a<b. 则有 若a,b 奇偶性相同,则 x=(b-a)/2. 不断更新~
/************************************************************************** user_id: SCNU20102200088 problem_id: hdoj 4143 problem_name: A Simple Problem **************************************************************************/ #include <algorithm> #include <iostream> #include <iterator> #include <iomanip> #include <sstream> #include <fstream> #include <cstring> #include <cstdlib> #include <climits> #include <bitset> #include <string> #include <vector> #include <cstdio> #include <cctype> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <list> #include <set> #include <map> using namespace std; //线段树 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 //手工扩展栈 #pragma comment(linker,"/STACK:102400000,102400000") const double EPS=1e-9; const double PI=acos(-1.0); const double E=2.7182818284590452353602874713526; //自然对数底数 const double R=0.5772156649015328606065120900824; //欧拉常数:(1+1/2+...+1/n)-ln(n) const int x4[]={-1,0,1,0}; const int y4[]={0,1,0,-1}; const int x8[]={-1,-1,0,1,1,1,0,-1}; const int y8[]={0,1,1,1,0,-1,-1,-1}; typedef long long LL; typedef int T; T max(T a,T b){ return a>b? a:b; } T min(T a,T b){ return a<b? a:b; } T gcd(T a,T b){ return b==0? a:gcd(b,a%b); } T lcm(T a,T b){ return a/gcd(a,b)*b; } /////////////////////////////////////////////////////////////////////////// //Add Code: const int INF=1000000000; /////////////////////////////////////////////////////////////////////////// int main(){ std::ios::sync_with_stdio(false); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); /////////////////////////////////////////////////////////////////////// //Add Code: int Case,n,i; scanf("%d",&Case); while(Case--){ scanf("%d",&n); int ans=INF; for(i=1;i<=sqrt(n);i++){ if(n%i==0){ int a=i,b=n/i; if(b-a>0 && (b-a)%2==0){ int x=(b-a)/2; if(x<ans) ans=x; } } } if(ans==INF) printf("-1\n"); else printf("%d\n",ans); } /////////////////////////////////////////////////////////////////////// return 0; } /************************************************************************** Testcase: Input: 2 2 3 Output: -1 1 **************************************************************************/
相关文章推荐
- hdoj 4143 A Simple Problem | hdoj 4206 Treasure Map
- Hdoj 4143 A Simple Problem
- HDOJ 4143 A Simple Problem
- HDOJ 4975 A simple Gaussian elimination problem.
- HDOJ 5349 MZL's simple problem 【set】
- 【DP】 HDOJ A simple greedy problem.
- hdoj 2522 A simple problem 【模拟】
- hdoj 1757 A Simple Math Problem
- HDOJ 4974 A simple water problem
- hdoj 2522 A simple problem
- HDU-4143 A Simple Problem
- hdoj 4971 A simple brute force problem. 【最大权闭合图 --> 最小割】
- hdoj 5974 A Simple Math Problem
- HDU 4143 A Simple Problem
- hdoj 5974 A Simple Math Problem(数学)
- hdoj 4976 A simple greedy problem.【dp】
- HDU 4143 A Simple Problem (枚举暴力)
- 【树状数组】 HDOJ 4276 A Simple Problem with Integers
- HDOJ 1757 A Simple Math Problem
- HDOJ 4267 A Simple Problem with Integers