BZOJ1202 [HNOI2005] cunning businessman and check set maintenance prefix and

Source: Internet
Author: User

1202: [HNOI2005] cunning businessman time limit:10 Sec Memory limit:162 MB
submit:1935 solved:936
[Submit] [Status] [Discuss] Description 刁姹 received a task to investigate a businessman's ledger for the tax department to see if the ledger was forged. The ledger records the income of n months, of which the amount of income for the first month is AI (i=1,2,3...n-1,n). When the AI is greater than 0, this month is the profit AI, when the AI is less than 0 represents this month loss of Ai Yuan. The so-called total revenue for a period of time is the sum of each month's income during this period. 刁姹 's mission was carried out in secret, and she had to run to the merchant to investigate the merchant's ledger. She peeked at the ledger while the businessman was away, but she could not steal the ledger, and every time she looked at the ledger she could only see the income recorded in the ledger for a certain period of time, and she could only remember the total revenue during that time. Now, Diao cha a total of peek at the M-Time ledger, of course, also remember the M period of total revenue, your task is to remember this information to determine whether the ledger is false. Input first behaves as a positive integer w, where W < 100, which indicates that there is a W-group of data, i.e. W Ledger, that you need to judge. The first behavior of each group of data is two positive integers n and M, where N < 100,m < 1000, respectively, indicate how many months of income the corresponding ledger records and how many times the ledger was peeped. The next M-line represents the M-piece of information that Diao Cha peeks into the M-Ledger, with each piece of information having three integers s,t and V, representing a total revenue of V from month s to T months (including T-month), where S is always less than or equal to T. Output contains w lines, each line is true or false, where I behaves true when and only if the group I is not false, that is, the I-Ledger is false, and if and only if the group I data, that is, the I ledger is false. Sample Input2
3 3
1 2 10
1 3-5
3 3-15
5 3
1 5 100
3 5 50
1 2 51
Sample Outputtrue
False
//1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineMemfy (a) memset (A,-1,sizeof (a))#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineMoD 1000000007#defineMAXN 106inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************intN,M,PARENT[MAXN],V[MAXN];voidInit () {for (I,0, N) parent[i]=I;mem (v);}intFindsintx) {    if(X==parent[x])returnx; intt=Parent[x]; PARENT[X]=finds (parent[x]); V[X]+=V[t]; returnparent[x];}intMain () {intt=read ();  while(t--) {n=read (); M=read ();         Init (); intflag=0, X,y,w; For (I,1, M) {scanf ("%d%d%d",&x,&y,&W); intFx=finds (x1); intfy=finds (Y); if(fx!=FY) {PARENT[FX]=fy; V[FX]=v[y]-v[x-1]+W; }Else if(v[x-1]-V[Y]!=W) flag=1; }         if(flag) printf ("false\n"); Elseprintf"true\n"); }    return 0;}
Code

BZOJ1202 [HNOI2005] cunning businessman and check set maintenance prefix and

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.