HDU4768 Flyer | The nature of the XOR | violence

Source: Internet
Author: User
Tags min printf cmath

Title Link: HDU4768

Test, can you show the picture

If a student takes an odd flyer, outputs its ID and the number of flyers, otherwise the output DC Qiang is unhappy.

Code from: Teammate @vectorhr + big guy's team @bhza8987510 (whu-Pan Junlin)

Here are two ways of doing it, the comments in the code are very clearly written, just look at the code.

AC Code 1:

/* August 25, 2017 11:15:13 HDU4768 Properties AC */#include <iostream> #include <map> #include <set> #include <string> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #
Include <stack> #include <vector> using namespace std;
const int maxn=2e5+5;
typedef long Long LL;

ll A[MAXN],B[MAXN],C[MAXN];
	int main () {ll n,res,sum;
		while (~SCANF ("%lld", &n)) {res=sum=0;
		memset (A,0,sizeof (a));
		Memset (b,0,sizeof (b));
		Memset (C,0,sizeof (c));
		for (ll i=1;i<=n;i++) {scanf ("%lld%lld%lld", &a[i],&b[i],&c[i]);
			} for (ll i=1;i<=n;i++) {for (ll j=a[i];j<=b[i];j+=c[i]) {//printf ("%lld^%lld=%lld\n", j,res,res^j);
			/* Here use the different or the same number of different or even several times the result is 0, XOR or odd number of its own, so if the res is 0, then each number has an even number of times, otherwise res is equal to the appearance of the odd number of the person's label. Very ingenious.
			Remember to open long long may explode */res^=j; }} if (res) {for (ll i=1;i<=n;i++) {/* statistics each group A,b,c contribution to this person, each group contributes up to 1*/if (Res>=a[i]&&res<=b[i] &&((Res-a[i])%c[i]) ==0) ++sum;
			}//printf ("Res=%lld", res);
		printf ("%lld%lld\n", res,sum);
		} else{printf ("DC Qiang is unhappy.\n");
}} return 0; }


AC Code 2:

/* August 25, 2017 11:19:04 HDU4758 binary Find AC */#include <iostream> #include <map> #include <set> #include &l t;string> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #
Include <stack> #include <vector> using namespace std;
const int MAXN=2E4+10;
typedef long Long LL;
const LL INF=0X3F3F3F3F;
ll A[MAXN],B[MAXN],C[MAXN];

ll tot;
	int main () {int n;
		while (~SCANF ("%d", &n)) {tot=0;
		ll Mx=-inf,mi=inf;
			for (int i=1;i<=n;i++) {scanf ("%lld%lld%lld", &a[i],&b[i],&c[i]);
			Mx=max (B[I],MX);
			Mi=min (A[I],MI);
		tot+= (b[i]-a[i])/c[i]+1;//sum of the number of leaflets contributed by each group of A,b,c ((tot&1) ==0) printf ("DC Qiang is unhappy.\n");
			else{//Use two points to find out the number of people who make the numbers of flyers odd. ll mid= (MX+MI) >>1;
			ll R=mx;
			ll L=mi;
				while (l<r) {tot=0;
					for (int i=1;i<=n;i++) {if (mid<a[i]) continue;
					else{tot+= (min (mid,b[i])-a[i])/c[i]+1;
				}} if ((tot&1) ==0) l=mid+1;else R=mid;
			Mid= (l+r) >>1;
			} ll Ans=0; for (int i=1;i<=n;i++) {/* counts each group A,B,C contribution to this person, each group contributes up to 1*/if (r>=a[i]&&r<=b[i]&& ((r-a[i))%c[i
			]==0)) ans++;
		} printf ("%lld%lld\n", R,ans);
}} 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.