2015
04-16

Porcelain Exhibitions

Recently, the Chinese government is going to hold a porcelain exhibition in every province.
For fascinating citizens, each exhibition should put at least MIN_K porcelains on show. And by the restriction of conditions, at most MAX_K porcelains can be shown in an exhibition.

The number of porcelains in a province is in direct proportion to the area of that province. So some small provinces may don’t have enough porcelains, and some big provinces may have more porcelains than it can show(having too much porcelains is not a problem for holding an exhibition, just don’t show some of them). The government decides to transport some porcelains between provinces so that every province can hold an exhibition.

Because of the limitation of traffic, the amount of porcelains passing a boundary between two provinces is limited. So the government asks you to write a program to manage the transportation.

The map of China can be seen as a connected planar graph embedded on a plane. Each face of the graph represents a province. This graph has N vertices and M edges. A vertex of the graph is also a point on the map, and an edge is also a line segment connecting two points, meaning a boundary between two provinces.

The input will consist of multiply test cases. For each case, The first line contains five positive integers — above mentioned N, M, MIN_K,MAX_K and P( N <= 1000,M <= 10000, MIN_K < MAX_K) . P means that if the area of a province is A, then there are A×P porcelains in that province. P is guaranteed to be even so that the amount of porcelains in each province will be a positive integer.

The next N lines, each gives two integer x, y, representing the coordinate of a vertex(Vertexes have distinct coordinates). The vertexes are numbered from 0 to N-1 and the coordinates are given in the order of vertex No.

The next M lines, each gives three integers u,v, and w. It means that there is an edge connecting vertex u and vertex v. The edge is also a boundary between two provinces. w means that the boundary can’t let more than w porcelains to pass through. (w for the boundary of China is 0, and boundaries don’t overlap). The number of province is less than 2000.
Unsigned int is enough for this problem. The input ends with 0 0 0 0 0.

The input will consist of multiply test cases. For each case, The first line contains five positive integers — above mentioned N, M, MIN_K,MAX_K and P( N <= 1000,M <= 10000, MIN_K < MAX_K) . P means that if the area of a province is A, then there are A×P porcelains in that province. P is guaranteed to be even so that the amount of porcelains in each province will be a positive integer.

The next N lines, each gives two integer x, y, representing the coordinate of a vertex(Vertexes have distinct coordinates). The vertexes are numbered from 0 to N-1 and the coordinates are given in the order of vertex No.

The next M lines, each gives three integers u,v, and w. It means that there is an edge connecting vertex u and vertex v. The edge is also a boundary between two provinces. w means that the boundary can’t let more than w porcelains to pass through. (w for the boundary of China is 0, and boundaries don’t overlap). The number of province is less than 2000.
Unsigned int is enough for this problem. The input ends with 0 0 0 0 0.

8 9 5 8 2
0 0
0 3
3 3
3 0
1 1
1 2
2 2
2 1
0 1 0
1 2 0
2 3 0
3 0 0
4 5 1
5 6 1
6 7 1
7 4 1
0 4 1
8 9 7 8 2
0 0
0 3
3 3
3 0
1 1
1 2
2 2
2 1
0 1 0
1 2 0
2 3 0
3 0 0
4 5 1
5 6 1
6 7 1
7 4 1
0 4 1
0 0 0 0 0

14
-1

1. #include <cstdio>
#include <cstring>

const int MAXSIZE=256;
//char store[MAXSIZE];
char str1[MAXSIZE];
/*
void init(char *store) {
int i;
store['A']=’V', store['B']=’W',store['C']=’X',store['D']=’Y',store['E']=’Z';
for(i=’F';i<=’Z';++i) store =i-5;
}
*/
int main() {
//freopen("input.txt","r",stdin);
//init(store);
char *p;
while(fgets(str1,MAXSIZE,stdin) && strcmp(str1,"STARTn")==0) {
if(p=fgets(str1,MAXSIZE,stdin)) {
for(;*p;++p) {
//*p=store[*p]
if(*p<’A’ || *p>’Z') continue;
if(*p>’E') *p=*p-5;
else *p=*p+21;
}
printf("%s",str1);
}
fgets(str1,MAXSIZE,stdin);
}
return 0;
}

2. 漂亮。佩服。
P.S. unsigned 应该去掉。换行符是n 不是/n
还可以稍微优化一下，
int main() {
int m,n,ai,aj,bi,bj,ak,bk;
while (scanf("%d%d",&m,&n)!=EOF) {
ai = sqrt(m-1);
bi = sqrt(n-1);
aj = (m-ai*ai-1)>>1;
bj = (n-bi*bi-1)>>1;
ak = ((ai+1)*(ai+1)-m)>>1;
bk = ((bi+1)*(bi+1)-n)>>1;
printf("%dn",abs(ai-bi)+abs(aj-bj)+abs(ak-bk));
}
}

3. 约瑟夫也用说这么长……很成熟的一个问题了，分治的方法解起来o(n)就可以了，有兴趣可以看看具体数学的第一章，关于约瑟夫问题推导出了一系列的结论，很漂亮