Numerator difference Beam example ZOJ 2770 fire-connected Camp

Source: Internet
Author: User

Source of the topic:
ZOJ Monthly, October 2006, ZOJ2770
Title Description:
As we all know, the Three Kingdoms period, Shu Liu Bei was defeated by the Wu Lu Xun governor. Liu Bei's failure was due to Liu Bei's mistake
Decision. He divided the army into dozens of barracks, each camp stationed a team of troops, and with the trees into a fence, the battalion into a piece,
Known as the company of the battalion.
Let's go back to that time. Lu Xun sent a lot of spies to get his enemy-Liu Bei's army information. Through Spies,
He knew that Liu Bei's army had been divided into dozens of of the camp, and the camp was a piece (lined up), which was used from left to right1...
NNumber. TheIA camp can accommodate up toCIA soldier. And by observing the movement of Liu Bei's army, Lu Xun can estimate theI
A camp to the firstJThere are at least a few soldiers in the camp. Finally, Lu Xun must estimate how many soldiers Liu Bei had at least, so that he knew
Theory, realization and application of graph theory algorithm
-196-
How many soldiers will be sent to burn Liu Bei's camp.
Input Description:
There are multiple test data in the input file. The first line of each test data, with two integersN (0<n≤1000)AndM (0≤M
≤10000)。 The second line, thereNAn integerC1...Cn。 Next thereMLine, each line has3 integer i, J, K (0<i ≤j≤n, 0< Span class= "Fontstyle0" >≤
k<231 i j k a soldier.
Output Description:
For each test data, output an integer, a row, for Lu Xun estimated how many soldiers at least Liu Bei Army. However, the estimates for
Lu Xun may not be accurate, and if not accurately estimated, the output Sample input: Sample output:
3 2
3 3
1 2 1100
2 1 1300
2
3
1300
Bad estimations

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 intn,m;6 structnode{7     int  from, To,value;8}e[25000];9 intei,c[ -],d[ -],dis[ -];//Dis Shortest PathTen //D Camp prefix and c maximum number of each camp One voidInit () A { -memset (DIS,0x3f,sizeof(DIS)); -d[0]=0;d is[n]=0; ei=0; the } - BOOLCheck () - { -      for(intI=0; i<n;i++){ +          for(intj=0; j<ei;j++){ -             if(Dis[e[j].to]>dis[e[j]. from]+e[j].value && Dis[e[i]. from]!=0x3f)//Slack +DIS[E[J].TO]=DIS[E[J]. from]+E[j].value; A         } at     } -      for(intI=0; i<ei;i++){ -         if(Dis[e[i]. from]+e[i].value<dis[e[i].to] && Dis[e[i]. from]!=0x3f) -           return false; -     } -     return true; in } - intMain () to { +      while(SCANF ("%d%d", &n,&m)! =EOF) -     { the init (); *          for(intI=1; i<=n;i++){ $scanf"%d",&c[i]);Panax NotoginsengE[ei]. from=i-1; e[ei].to=i;e[ei].value=c[i];ei++; -E[ei]. from=i;e[ei].to=i-1; e[ei].value=0; ei++; thed[i]=d[i-1]+C[i]; +         } A         intu,v,w; the          for(intI=0; i<m;i++){ +scanf"%d%d%d",&u,&v,&W); -E[ei]. from=v;e[ei].to=u-1; e[ei].value=w* (-1); ei++; $E[ei]. from=u-1; e[ei].to=v;e[ei].value=d[v]-d[u-1];ei++; $         } -         if(!check ()) printf ("Bad estimations\n"); -         Elseprintf"%d\n", dis[n]-dis[0]); the     } -     return 0;Wuyi}

Idea: to deal with each condition into an inequality (preferably all is greater than or all is less than), and then construct a map, run one side of the shortest test

&NBSP;

Numerator Bundle Example ZOJ 2770 Fire Connection Camp

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.