# 1000:a+b problem (NetWork Flow)

Source: Internet
Author: User

1000:a+b problem time limit:1 Sec Memory limit:5 MB
submit:11814 solved:7318
[Submit] [Status] [Discuss] Description

Calculate a+b

Input

Both integer A, B (0<=a,b<=10)

Output

Output a+b

Sample Input1 2Sample Output3HINT

Q:where is the input and the output? A:your program shall all read input from stdin, standard input, and write output to stdout (standard output). For example, you can use the ' scanf ' in C or ' cin ' in C + + to the read from stdin, and use ' printf ' in C or ' cout ' in C + + to write to stdout. You shall no output any extra data to standard output other than that required by the problem, otherwise you wil L Get a "wrong Answer". User programs is not allowed to open and read from/write to files. You'll get a "Runtime Error" or a "wrong Answer" if you try to do so. Here's a sample solution for problem-using c++/g++:

`using namespace Std;int  Main (){    int A, B;    Cin >> a >> b;    cout << a+b << Endl;    return 0;}`

It's important that the return type of main () must is int when you use g++/gcc,or you get compile error. Here's a sample solution for problem-using C/GCC:

`int main (){    int A, B;    scanf ("%d%d", &a, &b);    printf ("%d\n", a+b);    return 0;}`

Here's a sample solution for problem-using PASCAL:

`        End.`

Here's a sample solution for problem-using java:now JAVA compiler is JDK 1.5, next are program for 1000

`Import java.io.*;Import java.util.*;public class Main{            public static void Main (String args[]) throws Exception            {                    Scanner cin=new Scanner (system.in);                    int A=cin.nextint (), B=cin.nextint ();                    System.out.println (A+B);            }}`

Old program for JDK 1.4

`Import java.io.*;Import java.util.*;public class Main{    public static void Main (String args[]) throws Exception    {                    New BufferedReader (                New InputStreamReader (system.in));        String line = Stdin.readline ();        StringTokenizer st = new StringTokenizer (line);        int a = Integer.parseint (St.nexttoken ());        int b = Integer.parseint (St.nexttoken ());        System.out.println (A+B);    }}`

Source

Problem: Needless to say, a lot of Web sites have classic problems (Hansbug: Oh hehe ~ ~ ~ ~), until today I first use the network stream to do it = = or nothing to say, the direct source point and the meeting point with two Benquan respectively A and B have a forward edge, and then run SAP finished, specific look at the code
`1/**************************************************************2Problem: +3 User:hansbug4 language:pascal5 result:accepted6Time:0Ms7Memory:268KB8****************************************************************/9  Ten type OnePoint=^node; ANode=Record - G,w:longint; - Next,anti:point; the     End; - var - I,j,k,l,m,n,ans,s,t,x,y:longint; -A:Array[0.. +] ofPoint ; +D,DV:Array[0.. +] ofLongint; - functionmin (x,y:longint): Longint; +          begin A               ifX<y ThenMin:=xElsemin:=y; at          End; - procedureAdd (x,y,z:longint); -           varP:point; -           begin -New (p);p ^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p; -New (p);p ^.g:=x;p^.w:=0;p ^.next:=a[y];a[y]:=p; ina[x]^.anti:=a[y];a[y]^.anti:=A[x]; -           End; to functionDFS (x,flow:longint): Longint; +          varP:point;k:longint; -          begin the               ifX=t Thenexit (flow); *dfs:=0;p: =A[x]; \$                whileP<>Nil  DoPanax Notoginseng                     begin -                          if(p^.w<>0) and(D[x]= (d[p^.g]+1)) Then the                             begin +K:=dfs (P^.g,min (flow-dfs,p^.w)); A                                  ifP^.w<>maxlongint ThenDec (p^.w,k); the                                  ifP^.anti^.w<>maxlongint ThenInc (P^.ANTI^.W,K); +Inc (DFS,K);ifDfs=flow Thenexit; -                             End; \$p:=P^.next; \$                     End; -               ifD[s]=n Thenexit; - Dec (dv[d[x]]); the               ifdv[d[x]]=0  Thend[s]:=N; - Inc (D[x]); Inc (Dv[d[x]);Wuyi          End; the begin -READLN (x, y); n:=2; s:=1; t:=2; Wu       fori:=1  toN Doa[i]:=Nil; - Add (s,t,x); add (s,t,y); AboutFillchar (d,sizeof (d),0); \$Fillchar (Dv,sizeof (DV),0); -dv[0]:=n;ans:=0; -       whileD[s]<n DoInc (Ans,dfs (S,maxlongint)); - writeln (ans); A Readln; + End.`

1000:a+b problem (NetWork Flow)

Related Keywords:

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.