BC10hdoj5019&&hdoj5020
来源:互联网 发布:广州市软件创新人才 编辑:程序博客网 时间:2024/06/14 00:24
Revenge of GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1841 Accepted Submission(s): 512
Problem Description
In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), highest common factor (hcf), or greatest common measure (gcm), of two or more integers (when at least one of them is not zero), is the largest positive integer that divides the numbers without a remainder.
---Wikipedia
Today, GCD takes revenge on you. You have to figure out the k-th GCD of X and Y.
---Wikipedia
Today, GCD takes revenge on you. You have to figure out the k-th GCD of X and Y.
Input
The first line contains a single integer T, indicating the number of test cases.
Each test case only contains three integers X, Y and K.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= X, Y, K <= 1 000 000 000 000
Each test case only contains three integers X, Y and K.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= X, Y, K <= 1 000 000 000 000
Output
For each test case, output the k-th GCD of X and Y. If no such integer exists, output -1.
Sample Input
32 3 12 3 28 16 3
Sample Output
1-12
Source
BestCoder Round #10
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>using namespace std;const int maxn=2000010;long long num[maxn];queue<long long >Q;int main(){ int j,t; long long x,y,k,i; scanf("%d",&t); while(t--){ scanf("%lld%lld%lld",&x,&y,&k); long long cnt=0; for(i=1;i*i<=min(x,y);++i){ if(min(x,y)%i==0){ num[cnt++]=i; num[cnt++]=min(x,y)/i; if(i*i==min(x,y))cnt--; } } sort(num,num+cnt); for(i=cnt-1;i>=0;--i){ if(x%num[i]==0&&y%num[i]==0)k--; if(k==0)break; } if(k) printf("-1\n"); else printf("%lld\n",num[i]); } return 0;}
Revenge of Collinearity
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 571 Accepted Submission(s): 191
Problem Description
In geometry, collinearity is a property of a set of points, specifically, the property of lying on a single line. A set of points with this property is said to be collinear (often misspelled as colinear).
---Wikipedia
Today, Collinearity takes revenge on you. Given a set of N points in two-dimensional coordinate system, you have to find how many set of <Pi, Pj, Pk> from these N points are collinear. Note that <Pi, Pj, Pk> cannot contains same point, and <Pi, Pj, Pk> and <Pi, Pk, Pj> are considered as the same set, i.e. the order in the set doesn’t matter.
---Wikipedia
Today, Collinearity takes revenge on you. Given a set of N points in two-dimensional coordinate system, you have to find how many set of <Pi, Pj, Pk> from these N points are collinear. Note that <Pi, Pj, Pk> cannot contains same point, and <Pi, Pj, Pk> and <Pi, Pk, Pj> are considered as the same set, i.e. the order in the set doesn’t matter.
Input
The first line contains a single integer T, indicating the number of test cases.
Each test case begins with an integer N, following N lines, each line contains two integers Xi and Yi, describing a point.
[Technical Specification]
1. 1 <= T <= 33
2. 3 <= N <= 1 000
3. -1 000 000 000 <= Xi, Yi <= 1 000 000 000, and no two points are identical.
4. The ratio of test cases with N > 100 is less than 25%.
Each test case begins with an integer N, following N lines, each line contains two integers Xi and Yi, describing a point.
[Technical Specification]
1. 1 <= T <= 33
2. 3 <= N <= 1 000
3. -1 000 000 000 <= Xi, Yi <= 1 000 000 000, and no two points are identical.
4. The ratio of test cases with N > 100 is less than 25%.
Output
For each query, output the number of three points set which are collinear.
Sample Input
231 12 23 340 01 00 11 1
Sample Output
10
Source
BestCoder Round #10
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>#include<map>using namespace std;const int maxn=1010;map<double,int>K;struct Node{ int x,y;}A[maxn];int main(){ int n,i,j,k,t; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;++i){ scanf("%d%d",&A[i].x,&A[i].y); } int ans=0,num; for(i=0;i<n;++i){ K.clear();num=0; for(j=i+1;j<n;++j){ if(A[i].x==A[j].x){ ans+=num; num++; } else { ans+=K[(A[i].y-A[j].y)*1.0/(A[i].x-A[j].x)]; K[(A[i].y-A[j].y)*1.0/(A[i].x-A[j].x)]++; } } } printf("%d\n",ans); } return 0;}
0 0
- BC10hdoj5019&&hdoj5020
- HDOJ5020【几何】
- Tomcat项目部署方式
- BC9hdoj4993&&hdoj4994
- leetcode刷题,总结,记录,备忘 313
- objective-C : 工厂方法
- Struts2之OGNL类型转换
- BC10hdoj5019&&hdoj5020
- C++模板简介
- jQuery实践中发现的问题
- C#中获取日期之间天数的方法代码,及DataTime方法的日期格式整理
- [Lintcode]Minimum Depth of Binary Tree
- Recyclerview.getLayoutPosition()问题
- Struts2之自定义转换器
- Android中的PopupWindow详解
- SpreadButton,想拥有一个应用内的AssistiveTouch(助手按钮)吗