[HNOI2005] [BZOJ1202] A cunning businessman

Source: Internet
Author: User

1202: [HNOI2005] cunning businessman time limit:10 Sec Memory limit:162 MB
submit:1863 solved:899
[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
FalseHINT Source

The idea seems rather strange ... I didn't think it was a check-set.

And check the set maintenance of two arrays, f[i] means I where the and check set, V[i] f[i]->i month income, each read into S,t, p=f[s],q=f[t], if p==q, s,t belong to the same and check set, find F[s],f[t] in the process of maintenance office v[s], v[t],flag=v[t+1]-v[s]==w?1:0. If p!=q, the f[q] is assigned p, (leaving the left end of each set as the Father node, maintenance v[q]).

Another: Because the maintenance is the prefix and, so read into is can be t+1, Judge V[t+1]-v[s] value.

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;intf[ the],v[ the];intN,m,s,t,w,ww;BOOLFlag;intFindintx) {    if(f[x]==x)returnx; intpp=F[x]; F[X]=find (f[x]); V[X]+=V[PP]; returnf[x];}intMain () {scanf ("%d",&W);  while(w--) {memset (V,0,sizeof(v)); Flag=0; scanf ("%d%d",&n,&m);  for(intI=1; i<=n+1; i++) f[i]=i;  for(intI=1; i<=m;i++) {scanf ("%d%d%d",&s,&t,&ww); T++; intP=find (s), q=find (t); if(p==q) {if(v[t]-v[s]!=ww) {Flag=1;  Break; }            }            Else{F[q]=p; V[Q]=v[s]+ww-V[t]; }        }        if(flag) printf ("false\n");Elseprintf"true\n"); }    return 0;}

[HNOI2005] [BZOJ1202] A cunning businessman

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.