同余——HDU 4596

  • 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4596

  • 题意:给出N组数据X,Y,Z,判断是否存在两组数据,使得存在某一个数ID,使得 ID%X1=Y1||Z1 andID%X2=Y2||Z2

  • 分析:那么我们可以求出 X1X2 GCD 后,判 Y1,Z1 Y2,Z2 构成的4个差是否同余。

  • AC代码:

/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
#include <climits>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 1010
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
int N;
int X[MaxN], Y[MaxN], Z[MaxN];

int gcd(int a, int b)
{
    return b==0?a:gcd(b, a%b);
}

bool cal(int t, int a, int b, int c, int d)
{
    if( a%t==0 || b%t==0 || c%t==0 || d%t ==0 ) return true;
    return false;
}

bool judge(int i, int j)
{
    int t = gcd(X[i], X[j]);
    if( cal(t, Y[i]-Z[j], Z[i]-Y[j], Y[i]-Y[j], Z[i]-Z[j]) )
    {
        return true;
    }
    else return false;

}
int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d", &N))
    {
        for(int i=1;i<=N;i++) 
        {
            scanf("%d%d%d", &X[i], &Y[i], &Z[i]);
        }
        bool flag = false;
        for(int i=1;i<=N;i++)
        {
            for(int j=i+1;j<=N;j++)
            {
                if(judge(i,j))
                {
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag) puts("Cannot Take off");
        else puts("Can Take off");
    }

    //system("pause");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值