Going Home Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for e…
使用stringstream对象简化类型转换 C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性.类型安全和可扩展性.在本文中,我将展示怎样使用这些库来实现安全和自动的类型转换. 为什么要学习 如果你已习惯了<stdio.h>风格的转换,也许你首先会问:为什么要花额外的精力来学习基于<sstream>的类型转换呢?也许对下面一个简单的例子的回顾能够说服你.假设你想用sprintf()函数将一个变量从int类型…
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings t…
Drainage Ditches Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16314    Accepted Submission(s): 7748 Problem Description Every time it rains on Farmer John's fields, a pond forms over Bessie'…
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> #include<climits> using namespace std; int g[505][505]; int dx[505],dy[505]; bool vx[505], vy[505]; int dis[505]; int n, x, y; int res, minn; bool find(in…
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> const int maxn = 301; const int INF = (1<<31)-1; int w[maxn][maxn]; int lx[maxn],ly[maxn]; //顶标 int linky[maxn]; int visx[maxn],visy[maxn]; int slack[maxn…
#include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bool vis[505]; int linker[505]; void sscanf() { int x, y; scanf("%d%d",&n,&k); for(int i=1;i<=k;i++) { scanf("%d%d",&x,&am…
Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertica…
3308: 九月的咖啡店 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 244  Solved: 86 Description 深绘里在九份开了一家咖啡让,如何调配咖啡民了她每天的头等大事我们假设她有N种原料,第i种原料编号为i,调配一杯咖啡则需要在这里若干种兑在一起.不过有些原料不能同时在一杯中,如果两个编号为i,j的原料,当且仅当i与j互质时,才能兑在同一杯中.现在想知道,如果用这N种原料来调同一杯咖啡,使用的原料编号之和最大可为多少. In…
题意:给一个n*m的地图,'m'表示人,'H'表示房子,求所有人都回到房子所走的距离之和的最小值(距离为曼哈顿距离). 思路:比较明显的二分图最大权匹配模型,将每个人向房子连一条边,边权为曼哈顿距离的相反数(由于是求最小,所以先取反后求最大,最后再取反回来即可),然后用KM算法跑一遍然后取反就是答案.还可以用最小费用最大流做,方法是:从源点向每个人连一条边,容量为1,费用为0,从每个房子向汇点连一条边,容量为1,费用为0,从每个人向每个房子连一条边,容量为1,费用为曼哈顿距离的值,建好图后跑一遍…