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.
 

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
 

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.
 

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%.
 

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
原创粉丝点击