程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces 436 C. Dungeons and Candies

Codeforces 436 C. Dungeons and Candies

編輯:C++入門知識


MST....

C. Dungeons and Candies time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n?×?m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain identical candies, in this case the letters in the corresponding cells of the map will be the same.

\

When you transmit infZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcm1hdGlvbiB2aWEgYSBuZXR3b3JrLCB5b3Ugd2FudCB0byBtaW5pbWl6ZSB0cmFmZmljIKGqIHRoZSB0b3RhbCBzaXplIG9mIHRoZSB0cmFuc2ZlcnJlZCBkYXRhLiBUaGUgbGV2ZWxzIGNhbiBiZSB0cmFuc21pdHRlZCBpbiBhbnkgb3JkZXIuIFRoZXJlIGFyZSB0d28gd2F5cyB0byB0cmFuc21pdCB0aGUgY3VycmVudCBsZXZlbCA8ZW0+QTwvZW0+OjwvcD4KPG9sPgo8bGk+CllvdSBjYW4gdHJhbnNtaXQgdGhlIHdob2xlIGxldmVsIDxlbT5BPC9lbT4uIFRoZW4geW91IG5lZWQgdG8gdHJhbnNtaXQgPGVtPm48L2VtPqGkPGVtPm08L2VtPiBieXRlcwogdmlhIHRoZSBuZXR3b3JrLjxsaT4KWW91IGNhbiB0cmFuc21pdCB0aGUgZGlmZmVyZW5jZSBiZXR3ZWVuIGxldmVsIDxlbT5BPC9lbT4gYW5kIHNvbWUgcHJldmlvdXNseSB0cmFuc21pdHRlZCBsZXZ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GVuIGZvbGxvd3MgdGhlIGRlc2NyaXB0aW9uIG9mIDxlbT5rPC9lbT4gbGV2ZWxzLiBFYWNoIGxldmVsIGlzIGRlc2NyaWJlZCBieSA8ZW0+bjwvZW0+IGxpbmVzLAogZWFjaCBsaW5lIGNvbnRhaW5zIDxlbT5tPC9lbT4gY2hhcmFjdGVycy4gRWFjaCBjaGFyYWN0ZXIgaXMgZWl0aGVyIGEgbGV0dGVyIG9mIHRoZSBFbmdsaXNoIGFscGhhYmV0IG9yIGEgZG90ICg="."). Please note that the case of the letters matters.

Output

In the first line print the required minimum number of transferred bytes.

Then print k pairs of integers x1,?y1,?x2,?y2,?...,?xk,?yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first way, otherwise yi must be equal to the number of a previously transferred level. It means that you will transfer the difference between levels yi and xi to transfer level xi. Print the pairs in the order of transferring levels. The levels are numbered 1 through k in the order they follow in the input.

If there are multiple optimal solutions, you can print any of them.

Sample test(s) input
2 3 3 2
A.A
...
A.a
..C
X.Y
...
output
14
1 0
2 1
3 1
input
1 1 4 1
A
.
B
.
output
3
1 0
2 0
4 2
3 0
input
1 3 5 2
ABA
BBB
BBA
BAB
ABB
output
11
1 0
3 1
2 3
4 2
5 1

#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Edge
{
    int u,v,w;
}edge[1100*1100];

bool cmp(Edge a,Edge b)
{
    return a.w vc[1100];

int get_diff(char a[][20],char b[][20] )
{
    int ret=0;
    for(int i=0;i


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved