Hdu4596 yet another end of the world extends Euclidean Properties

Source: Internet
Author: User

I should have eaten this question. At first, the equation was wrong and I didn't want to think about the problem of connecting columns. I am really confused. If I can't do it, I should repeat it, fuck,

I gave N groups of X, Y, and Z and asked if there are two or more IDs. Yes, the value of ID % x is between the range [y, z, if yes, the output is cannot take off.

Otherwise you know


Based on the meaning of the question:

A * X1 + Y1 <= ID <= A * X1 + z1

B * X2 + y2 <= ID <= B * X2 + Z2,

If there is a solution, there must be duplicates between the two intervals, so continue to push:

A * X1 <= B * X2 + Z2 and B * X2 + y2 <= A * X1 + z1

Simplified to get

A * x1-B * X2 <= Z2-Y1 1 subaccount

B * x2-A * X1 <= Z1-Y2, expression 2

In order to unify the number 2

A * x1-B * X2 <= Y2-z1


Then we can see that we should think of extending Euclidean. If there is a non-negative and not all 0 integers A, B, there must be an integer pair X, Y to make gcd (A, B) = A * x + B * y,

To apply this question, gcd (x1, x2) = A * X1 + (-B * x2) is required, the sub-value of this formula is Z2-Y1 at the same time, so it is actually converted

The relationship between gcd (x1, x2) and Z2-Y1 is an integer multiple, meaning (z2-y1) % gcd (x1, x2) = 0, note that it is a modulo, I saw a question with a division number. When I tried to see other people's practices, I got a question and thought I was wrong, the problem is that someone else directly copied the parsing ~~~~~

At the same time, for Formula 2, we can also push to (Y2-Z1) %) gcd (x1, x2) = 0. either of the two can be satisfied, and the range coverage does not need to be strictly included, it's hard to tell the language clearly. I leave it to my mind.

N groups are given in the question. The range of N is 1000. You can simply scan two layers of violence to determine whether it is OK,


My judgment is as follows:


Int CAL (int A, int B, int c) {If (C % A = 0 | B % A = 0) return 1; // return 0 in case of equality of inequality ;}

The question judgment part of others is:

bool isok(int t,int le,int ri)  {      int i,j;      if(le%t==0||ri%t==0) return true ;      if(le<0&&ri>=0) return true ;      if(ri/t-le/t>0) return true ;      return false ;  }  

The judgment of all the online questions I have seen so far is exactly the same. All of them are as shown above, but I have missed the two if statements below, is the data on the subject too watery? The following two judgments I have not understood yet. Is there anything missing from my weak dish? If you pass by, ask me for advice,


# Include <iostream> # include <cstdio> # include <list> # include <algorithm> # include <cstring> # include <string> # include <queue> # include <stack> # include <map> # include <vector> # include <cmath> # include <memory. h ># include <set> # define ll long # define EPS 1e-8 # define INF 0 xfffffffconst ll INF = 1ll <61; using namespace STD; // vector <pair <int, int> G; // typedef pair <int, int> P; // vector <pair <int, int> >:: iterator ITER;/ /// Map <LL, int> MP; // Map <LL, int>: iterator P; const int n = 1000 + 5; int X [N], Y [N], Z [N]; void Init () {memset (x, 0, sizeof (x); memset (Y, 0, sizeof (y )); memset (z, 0, sizeof (z);} int gcd (int A, int B) {return B = 0? A: gcd (B, A % B);} int CAL (int A, int B, int C) {If (C % A = 0 | B % A = 0) return 1; // return 0 in case of equality of inequality;} int main () {int N; while (scanf ("% d", & n) = 1) {Init (); For (INT I = 0; I <n; I ++) scanf ("% d", & X [I], & Y [I], & Z [I]); bool flag = false; for (INT I = 0; I <n; I ++) {for (Int J = I + 1; j <n; j ++) {int TMP = gcd (X [I], X [J]); If (CAL (TMP, Z [J]-y [I], Y [J]-Z [I]) {flag = true ;}} if (FLAG) puts ("cannot take off "); else puts ("can take off");} return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.