1000: A+B Problem(NetWork Flow)
1000: A+B Problem
Time Limit: 1 Sec Memory Limit: 5 MB
Submit: 11814 Solved: 7318
Description
Calculate a+b
Input
Two integer a,b (0<=a,b<=10)
Output
Output a+b
Sample Input
1 2
Sample Output
3
HINT
Q: Where are the input and the output? A: Your program shall always read input from stdin (Standard Input) and write output to stdout (Standard Output). For example, you can use 'scanf' in C or 'cin' in C++ to read from stdin, and use 'printf' in C or 'cout' in C++ to write to stdout. You shall not output any extra data to standard output other than that required by the problem, otherwise you will get a "Wrong Answer". User programs are not allowed to open and read from/write to files. You will get a "Runtime Error" or a "Wrong Answer" if you try to do so. Here is a sample solution for problem 1000 using C++/G++:
#include
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 be int when you use G++/GCC,or you may get compile error. Here is a sample solution for problem 1000 using C/GCC:
#include
int main()
{
int a,b;
scanf("%d %d",&a, &b);
printf("%dn",a+b);
return 0;
}
Here is a sample solution for problem 1000 using PASCAL:
program p1000(Input,Output);
var
a,b:Integer;
begin
Readln(a,b);
Writeln(a+b);
end.
Here is a sample solution for problem 1000 using JAVA: Now java compiler is jdk 1.5, next is 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
{
BufferedReader stdin =
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
题解:不用说,很多网站上都有的经典题(HansBug:呵呵呵呵呵~~~),直到今天我才第一次用网络流来做它= =
还是没啥好说的,直接源点与汇点连两条边权分别为A和B的有向边,然后跑sap完事,具体看代码
1 /**************************************************************
2 Problem: 1000
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:0 ms
7 Memory:268 kb
8 ****************************************************************/
9
10 type
11 point=^node;
12 node=record
13 g,w:longint;
14 next,anti:point;
15 end;
16 var
17 i,j,k,l,m,n,ans,s,t,x,y:longint;
18 a:array[0..1000] of point;
19 d,dv:array[0..1000] of longint;
20 function min(x,y:longint):longint;
21 begin
22 if x<y then min:=x else min:=y;
23 end;
24 procedure add(x,y,z:longint);
25 var p:point;
26 begin
27 new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
28 new(p);p^.g:=x;p^.w:=0;p^.next:=a[y];a[y]:=p;
29 a[x]^.anti:=a[y];a[y]^.anti:=a[x];
30 end;
31 function dfs(x,flow:longint):longint;
32 var p:point;k:longint;
33 begin
34 if x=t then exit(flow);
35 dfs:=0;p:=a[x];
36 while p<>nil do
37 begin
38 if (p^.w<>0) and (d[x]=(d[p^.g]+1)) then
39 begin
40 k:=dfs(p^.g,min(flow-dfs,p^.w));
41 if p^.w<>maxlongint then dec(p^.w,k);
42 if p^.anti^.w<>maxlongint then inc(p^.anti^.w,k);
43 inc(dfs,k);if dfs=flow then exit;
44 end;
45 p:=p^.next;
46 end;
47 if d[s]=n then exit;
48 dec(dv[d[x]]);
49 if dv[d[x]]=0 then d[s]:=n;
50 inc(d[x]);inc(dv[d[x]]);
51 end;
52 begin
53 readln(x,y);n:=2;s:=1;t:=2;
54 for i:=1 to n do a[i]:=nil;
55 add(s,t,x);add(s,t,y);
56 fillchar(d,sizeof(d),0);
57 fillchar(dv,sizeof(dv),0);
58 dv[0]:=n;ans:=0;
59 while d[s]<n do inc(ans,dfs(s,maxlongint));
60 writeln(ans);
61 readln;
62 end.
- 神经网络算法交易:波动预测与定制损失函数
- 贝叶斯深度学习:桥接PyMC3和Lasagne构建层次神经网络
- How does it work in Mono's C# compiler?
- Cross-Origin Resource Sharing协议介绍
- 战斗民族开源神器ClickHouse:一款适合于构建量化回测研究系统的高性能列式数据库(二)
- Microsoft StreamInsight 构建物联网
- 利用 Microsoft StreamInsight 控制较大数据流
- HTML Agility Pack 搭配 ScrapySharp,彻底解除Html解析的痛苦
- 看看你是哪种级别的Python程序员(已跪)
- SignalR 在IE中无法工作 - Internet Explorer
- SQL Server 2012 中的 Service Broker功能的一些改进或增强
- 通用日志
- 数据包络分析教程
- 用JAVA的DEA算法衡量社交媒体页面的流行度
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 删除处于Terminating状态的namespace
- elasticSearch学习(七)
- Flutter透明度渐变动画FadeTransition实现透明度渐变动画效果
- iOS NSTimer不走的问题
- 我对python中的super()机制的一点理解
- 【Python】使用Pygame做一个Flappy bird小游戏(五)
- 【动手学深度学习笔记】之自定义层
- Ubuntu18.04系统安装和必备软件安装指南
- 如何查看微信好友已撤回的消息?
- 【Python爬虫】写一个爬取中国天气网的终端版天气预报爬虫
- 如何制定企业级代码规范与检查
- 哈希表:可以拿数组当哈希表来用,但哈希值不要太大!
- 【Python】Scrapy爬虫入门(一)Scrapy的基本用法和爬取静态网站
- 【动手学深度学习笔记】之读取和存储
- 据说这才是看热搜的正确方法?