锘??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涓偣錛屽強m鏉¤竟鐨勬渶澶ц礋杞斤紝姹傞《鐐?鍒伴《鐐筺鐨勬渶澶ф祦銆?/pre>
鐢―ijkstra綆楁硶瑙d箣錛屽彧鏄渶瑕佹妸“鏈鐭礬”鐨勫畾涔夌◢寰敼鍙樹竴涓嬶紝
A鍒癇鐨勮礬闀垮畾涔変負璺緞涓婅竟鏉冩渶灝忕殑閭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

#include <iostream>
using namespace std;
const int mod=10007;
int pow(int n)

{
if(n==0)
return 1;
if(n&1)
{
return (pow(n-1)<<1)%mod;
}
else
{
int temp=pow(n>>1);
return (temp*temp)%mod;
}
}
int main(int argc, char *argv[])

{
int t,n,temp;
cin>>t;
while(t--)
{
cin>>n;
temp=pow((n-1)%(mod-1));
cout<<(temp*(temp+1))%mod<<endl;
}
return 0;
}
| 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
#include聽<iostream>
using聽namespace聽std;
long聽long聽gcd(long聽long聽a,long聽long聽b)

{
聽聽聽聽if(a==0)
聽聽聽聽聽聽聽聽return聽b;
聽聽聽聽return聽gcd(b%a,a);
}
long聽long聽Eu(long聽long聽m,long聽long聽n)

{
聽聽聽聽if(m==1)
聽聽聽聽聽聽聽聽return聽1;
聽聽聽聽if(n-m==1聽&&聽m)
聽聽聽聽聽聽聽聽return聽0;
聽聽聽聽if(n>=m*2-1)
聽聽聽聽聽聽聽聽return聽1;
聽聽聽聽return聽!Eu(n%m,m);
}
int聽聽main()

{
聽聽聽聽long聽long聽m,n,temp;
聽聽聽聽while聽(cin>>m>>n聽&&聽(m||n))
聽聽聽聽
{
聽聽聽聽聽聽聽聽long聽long聽g=gcd(m,n);
聽聽聽聽聽聽聽聽m/=g;
聽聽聽聽聽聽聽聽n/=g;
聽聽聽聽聽聽聽聽if(m>n)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽temp=m;
聽聽聽聽聽聽聽聽聽聽聽聽m=n;
聽聽聽聽聽聽聽聽聽聽聽聽n=temp;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(Eu(m,n))
聽聽聽聽聽聽聽聽聽聽聽聽cout<<"Stan聽wins"<<endl;
聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽cout<<"Ollie聽wins"<<endl;
聽聽聽聽}
聽聽聽聽
聽聽聽聽return聽0;
}

| 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

/**//*Source聽Code
Problem:聽2153聽聽User:聽y09
Memory:聽1236K聽聽Time:聽1204MS聽
Language:聽C++聽聽Result:聽Accepted聽
Source聽Code聽*/
#include聽<iostream>
#include<string>
#include<map>
using聽namespace聽std;
int聽main(int聽argc,聽char聽*argv[])

{
聽聽聽聽int聽n,m;
聽聽聽聽int聽i,j;
聽聽聽聽char聽str[200];
聽聽聽聽string聽str1;
聽聽聽聽
聽聽聽聽map<string聽,int>score;
聽聽聽聽
聽聽聽聽scanf("%d",&n);
聽聽聽聽getchar();

聽聽聽聽for聽(i=0;i<n;i++聽)
聽聽聽聽
{
聽聽聽聽聽聽聽聽gets(str);
聽聽聽聽聽聽聽聽str1=str;
聽聽聽聽聽聽聽聽score[str1]=0;
聽聽聽聽}
聽聽聽聽
聽聽聽聽int聽cnt[5005]=
{0};
聽聽聽聽
聽聽聽聽scanf("%d",&m);
聽聽聽聽string聽li="Li聽Ming";
聽聽聽聽int聽rank=0;
聽聽聽聽int聽s=0;
聽聽聽聽int聽temp=0;
聽聽聽聽int聽temp2=0;
聽聽聽聽int聽num;
聽聽聽聽for(int聽k=0;k<m;k++)
聽聽聽聽
{
聽聽聽聽聽聽聽聽for(i=0;i<n;i++)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽scanf("%d",&num);
聽聽聽聽聽聽聽聽聽聽聽聽getchar();
聽聽聽聽聽聽聽聽聽聽聽聽gets(str);
聽聽聽聽聽聽聽聽聽聽聽聽str1=str;
聽聽聽聽聽聽聽聽聽聽聽聽temp2=score[str1];
聽聽聽聽聽聽聽聽聽聽聽聽score[str1]=num+temp2;
聽聽聽聽聽聽聽聽聽聽聽聽cnt[num+temp2]++;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽s=score[li];
聽聽聽聽聽聽聽聽rank=1;
聽聽聽聽聽聽聽聽temp+=100;
聽聽聽聽聽聽聽聽for(i=temp;i>s;i--)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽rank+=cnt[i];
聽聽聽聽聽聽聽聽聽聽聽聽cnt[i]=0;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽for(i=s;i>=0;i--)
聽聽聽聽聽聽聽聽聽聽聽聽cnt[i]=0;
聽聽聽聽聽聽聽聽printf("%d\n",rank);
聽聽聽聽}
聽聽聽聽return聽0;
}

| 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


#include <stdio.h>
int main(int argc, char *argv[])

{
int n,m;
int z,w1,w2;
int t;
int a,b,c;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
z=n-(m+2)/2;
w1=(m-1)/2;
w2=z-w1;
a=0;
while (z)
{
z>>=1;
a+=z;
}
b=0;
while (w1)
{
w1>>=1;
b+=w1;
}
c=0;
while (w2)
{
w2>>=1;
c+=w2;
}
printf("%d\n",(a-b-c)==0);
}
return 0;
}
| 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

/**//*Source Code
Problem: 3318 User: y09
Memory: 3080K Time: 1063MS
Language: C Result: Accepted 
Source Code */
#include <stdio.h>
#include <time.h>
#include<stdlib.h>
int main()

{
int n;
int i,j;
int mat1[500][500];
int mat2[500][500];
int mat3[500][500];
__int64 te1[500]=
{0};
__int64 te2[500]=
{0};
__int64 te3[500]=
{0};
__int64 te4[500]=
{0};
time_t t;
srand((unsigned) time(&t));
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mat1[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mat2[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&mat3[i][j]);
for(i=0;i<n;i++)
te1[i]=rand()%100;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
te2[i]+=te1[j]*mat1[j][i];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
te3[i]+=te2[j]*mat2[j][i];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
te4[i]+=te1[j]*mat3[j][i];
for(i=0;i<n;i++)
if(te3[i]!=te4[i])
{
puts("NO");
return 0;
}
puts("YES");

return 0;
}

| 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

/**//*Source Code
Problem: 1195 User: y09
Memory: 4956K Time: 579MS
Language: C++ Result: Accepted 
Source Code */
#include <stdio.h>
const int MAX=1200;
int c[MAX][MAX];
int n;
int LowBit(int t)

{
return t&(t^(t-1));
}
int Sum(int endx,int endy)

{
int sum=0;
int temp=endy;
while(endx>0)
{
endy=temp;//娉ㄦ剰璁板綍endy鐨勫鹼紝鏈漢鍦ㄦ鍑洪敊錛屾壘鍗婂ぉ閿欒涓嶅緱
while (endy>0)
{
sum+=c[endx][endy];
endy-=LowBit(endy);
}
endx-=LowBit(endx);
}
return sum;
}
void plus(int posx,int posy,int num)

{
int temp=posy;
while (posx <=n)
{
posy=temp;
while(posy<=n)
{
c[posx][posy]+=num;
posy+=LowBit(posy);
}
posx+=LowBit(posx);
}
}
int GetSum(int l,int b,int r,int t)

{
return Sum(r,t)-Sum(r,b-1)-Sum(l-1,t)+Sum(l-1,b-1);
}
int main()

{
int I;
int x,y,a;
int l,b,r,t;
while(scanf("%d",&I))
{
switch (I)
{
case 0:
scanf("%d",&n);
break;
case 1:
scanf("%d%d%d",&x,&y,&a);
plus(x+1,y+1,a);
break;
case 2:
scanf("%d%d%d%d",&l,&b,&r,&t);
printf("%d\n",GetSum(l+1,b+1,r+1,t+1));
break;
case 3:
return 0;
}
}
return 0;
}
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瀵瑰驚鐜妭鐨勯暱搴﹀彇妯″嵆鍙?
#include <iostream>
using namespace std;
int main()

{
const int MAX=300;//鏈澶ч暱搴?/span>
char str[MAX];//璇誨叆涓?/span>
int n;//鍙樻崲鐨勯暱搴?/span>

int data[MAX]=
{0};//瀛樻斁鍘熷鍙樻崲
int used[MAX]=
{0};//鏍囧織鏁扮粍
int cir[MAX][MAX]=
{0};//姣忎釜寰幆鑺傜殑鎴愬憳
int num[MAX]=
{0};//寰幆鑺傚搴旈暱搴?/span>
int cnt=0;//寰幆鑺傜殑涓暟
int time=0;//鍙樻崲嬈℃暟
int change[MAX]=
{0};//鍘熷寰幆鍙樻崲time嬈′箣鍚庣殑鍙樻崲

char res[MAX]=
{0};//鍙樻崲涔嬪悗鐨勫瓧絎︿覆

int i,j;
while(cin>>n && n)
{
memset(used,0,sizeof(used));
memset(num,0,sizeof(num));
for(i=1;i<=n;i++)
cin>>data[i];
cnt=0;//璁℃暟寰幆鑺備釜鏁?/span>
for(i=1;i<=n;i++)
{
if(used[i]==0)
{
used[i]=1;
int temp=data[i];
cir[cnt][num[cnt]]=temp;
num[cnt]=1;
while(used[temp]==0)//鑾峰緱寰幆鑺?/span>
{
used[temp]=1;
temp=data[temp];
cir[cnt][num[cnt]++]=temp;
}
cnt++;
}
}
while(cin>>time && time)//璇誨叆鍙樻崲嬈℃暟
{
memset(res,0,sizeof(res));
memset(str,0,sizeof(str));
gets(str);
int len=strlen(str);
for(i=len;i<=n;i++)//浣嶆暟涓嶈凍n,琛ョ┖鏍?/span>
str[i]=' ';
//鑾峰緱鍙樻崲
for(i=0;i<cnt;i++)
{
for(j=0;j<num[i];j++)
{
change[cir[i][j]]=cir[i][(j+time)%num[i]];
}
}
//瀵硅鍏ユ暟鎹彉鎹?鑾峰緱緇撴灉
for(i=1;i<=n;i++)
{
res[change[i]]=str[i];
}
cout<<res+1<<endl;
}
cout<<endl;
}
return 0;
}

/**//*Source CodeProblem: 2785 User: y09shendazhi
Memory: 160132K Time: 2610MS
Language: G++ Result: Accepted
Source Code*/
#include <iostream>
#include<stdio.h>
using namespace std;
const int size=20345677;
int hash[size];
int sum[size];
const int key=1777;
const int MAX=1000000000;
void Insert(int num)

{
int temp=num;
num=(num+MAX)%size;
while(hash[num]!=MAX && hash[num]!=temp)
num=(key+num)%size;
hash[num]=temp;
sum[num]++;
}
int Find(int num)

{
int temp=num;
num=(num+MAX)%size;
while(hash[num]!=MAX && hash[num]!=temp)
num=(num+key)%size;
if(hash[num]==MAX)
return 0;
else
return sum[num];
}
int main()

{
int n;
int i,j;
int a[4005],b[4005],c[4005],d[4005];
scanf("%d",&n);
int ans=0;
for(i=0;i<n;i++)
{
scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
}
for(i=0;i<size;i++)
{
hash[i]=MAX;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
Insert(a[i]+b[j]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
ans+=Find(-(c[i]+d[j]));
}
printf("%d\n",ans);
return 0;
}
/**//*Source CodeProblem: 3088 User: y09shendazhi
Memory: 164K Time: 0MS
Language: C++ Result: Accepte/
Source Code*/
#include <iostream>
using namespace std;
// /n\
// | |
// \m/
__int64 comb(__int64 m,__int64 n)

{
if(n<m)
return 0;
__int64 result=1;
m=m<n-m?m:n-m;
for(__int64 i=1;i<=m;i++)
result=(result*(n-m+i))/i;
return result;
}
__int64 fun(__int64 n)

{
__int64 ans=1;
for(__int64 i=1;i<=n;i++)
ans*=i;
return ans;
}
int main(__int64 argc, char *argv[])

{
__int64 i,j,k;
__int64 stir[15][15]=
{0};
for(i=1;i<12;i++)
{
stir[i][1]=1;
for(j=2;j<i;j++)
{
stir[i][j]=stir[i-1][j-1]+j*stir[i-1][j];
}
stir[i][i]=1;
}
__int64 ans[12]=
{0,1};
for(i=2;i<12;i++)
{
for(j=1;j<=i;j++)
{
__int64 temp=0;
for(k=1;k<=j;k++)
{
temp+=stir[j][k]*fun(k);
}
ans[i]+=temp*comb(j,i);
}
}
__int64 in=0;
__int64 t=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&in);
printf("%I64d %I64d %I64d\n",i+1,in,ans[in]);
}

return 0;
}