锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Description Input Output Sample Input Sample Output
Time Limit: 3000MS
Memory Limit: 30000K
Total Submissions: 5123
Accepted: 1393
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.1
3 3
1 2 3
1 3 4
2 3 5
Scenario #1:
4
緇欏畾n涓偣錛屽強(qiáng)m鏉¤竟鐨勬渶澶ц礋杞斤紝姹傞《鐐?鍒伴《鐐筺鐨勬渶澶ф祦銆?/pre>
鐢―ijkstra綆楁硶瑙d箣錛屽彧鏄渶瑕佹妸“鏈鐭礬”鐨勫畾涔夌◢寰敼鍙樹竴涓嬶紝
A鍒癇鐨勮礬闀垮畾涔変負(fù)璺緞涓婅竟鏉冩渶灝忕殑閭f潯杈圭殑闀垮害錛?/pre>
鑰屾渶鐭礬鍏跺疄鏄疉鍒癇鎵鏈夎礬闀跨殑鏈澶у箋?/pre>
//Heavy Transportation
//Dijkstra
#include <iostream>
#include<stdio.h>
using namespace std;
const int MAXS=1005;
int n;
int mat[MAXS][MAXS];
int asd[MAXS];
int s[MAXS];
int min(int a,int b)
{return a<b?a:b;}
int Dijkstra()
{
int i,j;
for(i=1;i<n;i++)
{
asd[i]=mat[0][i];
s[i]=0;
}
s[0]=1;
asd[0]=0;
for(i=0;i<n-1;i++)
{
int max=0;
int u=0;
for(j=1;j<n;j++)
{
if(s[j]==0 && asd[j]>max)
{
u=j;
max=asd[j];
}
}
if(u==0)
break;
s[u]=1;
asd[u]=max;
for(j=1;j<n;j++)
{
if (s[j]==0 && asd[j]<min(asd[u],mat[u][j]))
{
asd[j]=min(asd[u],mat[u][j]);
}
}
}
return asd[n-1];
}
int main()
{
int t,m;
int i,j;
scanf("%d",&t);
int v1,v2;
int value;
for (int s=1;s<=t;s++)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
for (j=0;j<n;j++)
{
mat[i][j]=0;
}
while (m--)
{
scanf("%d%d%d",&v1,&v2,&value);
mat[v1-1][v2-1]=mat[v2-1][v1-1]=value;
}
printf("Scenario #%d:\n%d\n\n",s,Dijkstra());
}
return 0;
}
]]>
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 720 | Accepted: 201 |
Description
Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue, green or yellow. For some myterious reasons, Panda want both the number of red blocks and green blocks to be even numbers. Under such conditions, Panda wants to know the number of different ways to paint these blocks.
Input
The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integer N(1≤N≤10^9) indicating the number of blocks.
Output
For each test cases, output the number of ways to paint the blocks in a single line. Since the answer may be quite large, you have to module it by 10007.
Sample Input
2 1 2
Sample Output
2 6
Source
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4525 | Accepted: 1849 |
Description
25 7
11 7
4 7
4 3
1 3
1 0
Input
Output
Sample Input
34 12 15 24 0 0
Sample Output
Stan wins Ollie wins
Source
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 6561 | Accepted: 2091 |
Description
Input
Output
Sample Input
3 Li Ming A B 2 49 Li Ming 49 A 48 B 80 A 85 B 83 Li Ming
Sample Output
1 2
Source
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1040 | Accepted: 346 |
Description
{1, 2, 3} U {4}, {1, 2, 4} U {3}, {1, 3, 4} U {2}, {2, 3, 4} U {1}
{1, 2} U {3, 4}, {1, 3} U {2, 4}, {1, 4} U {2, 3}.
S(0, 0) = 1; S(n, 0) = 0 for n > 0; S(0, m) = 0 for m > 0;
S(n, m) = m S(n - 1, m) + S(n - 1, m - 1), for n, m > 0.
S(4, 2) mod 2 = 1.
Input
Output
Sample Input
1 4 2
Sample Output
1
Source
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 11924 | Accepted: 2408 |
Description
You are given three n × n matrices A, B and C. Does the equation A × B = C hold true?
Input
The first line of input contains a positive integer n (n ≤ 500) followed by the the three matrices A, B and C respectively. Each matrix's description is a block of n × n integers.
It guarantees that the elements of A and B are less than 100 in absolute value and elements of C are less than 10,000,000 in absolute value.
Output
Output "YES" if the equation holds true, otherwise "NO".
Sample Input
2 1 0 2 3 5 1 0 8 5 1 10 26
Sample Output
YES
Hint
Source
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 7087 | Accepted: 3030 |
Description
Input
Output
Sample Input
0 4 1 1 2 3 2 0 0 2 2 1 1 1 2 1 1 2 -1 2 1 1 2 3 3
Sample Output
3 4
Source
Description
Bob and Alice started to use a brand-new encoding scheme. Surprisingly it is not a Public Key Cryptosystem, but their encoding and decoding is based on secret keys. They chose the secret key at their last meeting in Philadelphia on February 16th, 1996. They chose as a secret key a sequence of n distinct integers, a1 ; . . .; an, greater than zero and less or equal to n. The encoding is based on the following principle. The message is written down below the key, so that characters in the message and numbers in the key are correspondingly aligned. Character in the message at the position i is written in the encoded message at the position ai, where ai is the corresponding number in the key. And then the encoded message is encoded in the same way. This process is repeated k times. After kth encoding they exchange their message.
The length of the message is always less or equal than n. If the message is shorter than n, then spaces are added to the end of the message to get the message with the length n.
Help Alice and Bob and write program which reads the key and then a sequence of pairs consisting of k and message to be encoded k times and produces a list of encoded messages.
Input
The input file consists of several blocks. Each block has a number 0 < n <= 200 in the first line. The next line contains a sequence of n numbers pairwise distinct and each greater than zero and less or equal than n. Next lines contain integer number k and one message of ascii characters separated by one space. The lines are ended with eol, this eol does not belong to the message. The block ends with the separate line with the number 0. After the last block there is in separate line the number 0.
Output
Output is divided into blocks corresponding to the input blocks. Each block contains the encoded input messages in the same order as in input file. Each encoded message in the output file has the lenght n. After each block there is one empty line.
Sample Input
10
4 5 3 7 2 8 1 6 10 9
1 Hello Bob
1995 CERC
0
0
Sample Output
BolHeol b
C RCE
Source
Central Europe 1995
緇欏畾1~n鐨勭疆鎹,姹傚叾鍙樻崲m嬈$殑鍙樻崲F^m.
鍏堟壘鍒板驚鐜妭,鍐嶇敤m瀵瑰驚鐜妭鐨勯暱搴﹀彇妯″嵆鍙?