国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

HDU3038 How Many Answers Are Wrong(帶權并查集)

2019-11-06 06:38:24
字體:
來源:轉載
供稿:網友

題目:

How Many Answers Are Wrong

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7113    Accepted Submission(s): 2628PRoblem DescriptionTT and FF are ... friends. Uh... very very good friends -________-bFF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of integers-_-!!(bored).
Then, FF can choose a continuous subsequence from it(for example the subsequence from the third to the fifth integer inclusively). After that, FF will ask TT what the sum of the subsequence he chose is. The next, TT will answer FF's question. Then, FF can redo this process. In the end, FF must work out the entire sequence of integers.Boring~~Boring~~a very very boring game!!! TT doesn't want to play with FF at all. To punish FF, she often tells FF the wrong answers on purpose.The bad boy is not a fool man. FF detects some answers are incompatible. Of course, these contradictions make it difficult to calculate the sequence.However, TT is a nice and lovely girl. She doesn't have the heart to be hard on FF. To save time, she guarantees that the answers are all right if there is no logical mistakes indeed.What's more, if FF finds an answer to be wrong, he will ignore it when judging next answers.But there will be so many questions that poor FF can't make sure whether the current answer is right or wrong in a moment. So he decides to write a program to help him with this matter. The program will receive a series of questions from FF together with the answers FF has received from TT. The aim of this program is to find how many answers are wrong. Only by ignoring the wrong answers can FF work out the entire sequence of integers. Poor FF has no time to do this job. And now he is asking for your help~(Why asking trouble for himself~~Bad boy) InputLine 1: Two integers, N and M (1 <= N <= 200000, 1 <= M <= 40000). Means TT wrote N integers and FF asked her M questions.Line 2..M+1: Line i+1 contains three integer: Ai, Bi and Si. Means TT answered FF that the sum from Ai to Bi is Si. It's guaranteed that 0 < Ai <= Bi <= N.You can assume that any sum of subsequence is fit in 32-bit integer. OutputA single line with a integer denotes how many answers are wrong. Sample Input
10 51 10 1007 10 281 3 324 6 416 6 1 Sample Output
1 Source2009 Multi-University Training Contest 13 - Host by HIT Recommendgaojie   |   We have carefully selected several similar problems for you:  3033 3035 3036 3037 3031 思路:

題意:有 n 個數,你不知道它們的值, 然后又有 m 行數,每行 a ,b ,c,表示 a 到 b 之間所有數的和為c(包含了第a個和第b個數)。但是這m行數里面有些是錯的,就是與前面給的條件相沖突的,要求你最后輸出錯了幾行。用r錄每一個點跟根節點的關系。首先我們可以把問題稍微轉化一下,就是如果已知[3,6],[7,10]倆個區間內各自所有數的和,那么就可以[3,10]內所有數的和,可是,這倆個區間根本就不銜接,所有要稍微處理一下,將左區間值減1,就變成了[2,6],[6,10],這樣就方便處理了。既然這樣的話,[2,6]區間內所有數的和就完全可以等價于點2到點7之間的距離了。代碼:

#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <string>#include <iostream>#include <stack>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define N 1000+20#define M 200010#define MOD 1000000000+7#define inf 0x3f3f3f3fusing namespace std;int n,m;int f[M],r[M];void init()//初始化并查集{    for(int i=0; i<=n; i++)    {        f[i]=i;        r[i]=0;    }}int find(int x){    if(x==f[x])        return f[x];    int t=find(f[x]);    r[x]+=r[f[x]];//r[x]表示x到f[x]的距離,r[f[x]]表示的是父節點與根節點之間的距離    f[x]=t;    return f[x];}int func(int x,int y){    if(x>y)        return x-y;    else        return y-x;}int mix(int x,int y,int sum){    int fx=find(x);    int fy=find(y);    if(fx==fy)    {        if(func(r[x],r[y])==sum)            return 0;        else            return 1;//有錯誤了就返回1    }    else    {        f[fx]=fy;        r[fx]=sum+(r[y]-r[x]);        return 0;    }}int main(){    while(~scanf("%d%d",&n,&m))    {        int a,b,v,ans=0;        init();        for(int i=1; i<=m; i++)        {            scanf("%d%d%d",&a,&b,&v);            a--;//左值-1方便處理            if(mix(a,b,v))                ans++;        }        printf("%d/n",ans);    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 梅州市| 延津县| 汉沽区| 稷山县| 麻城市| 林甸县| 清丰县| 上林县| 秭归县| 安泽县| 樟树市| 东乡| 莲花县| 苏尼特右旗| 天气| 丹阳市| 咸阳市| 大城县| 虹口区| 阜新| 缙云县| 凤城市| 梅州市| 海兴县| 宜兰市| 平塘县| 镇坪县| 湘潭县| 五指山市| 中山市| 大邑县| 武川县| 许昌市| 团风县| 西峡县| 桐庐县| 普定县| 长治县| 普陀区| 留坝县| 靖远县|