锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久久久久久久,久久精品国产亚洲av影院,国产成人精品久久http://www.shnenglu.com/sdz/zh-cnSun, 29 Jun 2025 07:43:30 GMTSun, 29 Jun 2025 07:43:30 GMT60poj 1797 Heavy Transportation 鏈鐭礬http://www.shnenglu.com/sdz/archive/2010/09/01/125487.html鑻ヤ綑鑻ヤ綑Wed, 01 Sep 2010 01:28:00 GMThttp://www.shnenglu.com/sdz/archive/2010/09/01/125487.htmlhttp://www.shnenglu.com/sdz/comments/125487.htmlhttp://www.shnenglu.com/sdz/archive/2010/09/01/125487.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/125487.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/125487.htmlHeavy Transportation
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 5123 Accepted: 1393

Description

Background
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.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

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;
}



鑻ヤ綑 2010-09-01 09:28 鍙戣〃璇勮
]]>poj 3734 Blocks 鐢熸垚鍑芥暟http://www.shnenglu.com/sdz/archive/2010/08/31/125347.html鑻ヤ綑鑻ヤ綑Tue, 31 Aug 2010 01:28:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/31/125347.htmlhttp://www.shnenglu.com/sdz/comments/125347.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/31/125347.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/125347.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/125347.html      Blocks

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



緇欏畾涓鍧楁湁n涓偣鐨勬湪鍧楋紝鐢ㄥ洓縐嶉鑹叉秱鑹詫紝鍏朵腑涓ょ棰滆壊鍙兘鐢ㄥ伓鏁版錛屾眰鏈夊灝戠娑傝壊鏂規(guī)硶銆?br>
涓鐪嬪氨鐭ユ槸鐢熸垚鍑芥暟錛屽彲鎯滀粠娌$敤榪囥傚皬璇曡韓鎵嬶紝娌℃兂鍒扮珶鐒跺紕鍑烘潵浜嗐傜粨鏋滃簲璇ユ槸瀵圭殑錛屽氨鏄笉鐭ヨ繃紼嬫槸涓嶆槸鍙互榪欐牱鍐欍?br>璁懼洓縐嶉鑹插垎鍒負(fù)w錛寈錛寉錛寊錛屽叾涓瓂錛寊鍙兘鐢ㄥ伓鏁版錛屾垜鐨勬帹瀵艱繃紼嬪涓嬶細(xì)

鏈鍚庡緱鍒扮殑鍏紡鏄?2^( n - 1 ))(2^(n-1)+1)
娉ㄦ剰鍒?0007鏄礌鏁?鐢辮垂灝?dāng)椹畾鐞?鍙互鍏堟妸n-1mod錛?0007-1錛?鍑忓皬璁$畻閲?鍓╀笅鐨勫氨鏄揩閫熷彇騫備簡.
#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;
}

//鐢變簬榪戞棩POJ鐧諱笉涓婏紝涓婇潰鐨勪唬鐮佹湭鏇炬彁浜よ繃


鑻ヤ綑 2010-08-31 09:28 鍙戣〃璇勮
]]>
poj 2348 Euclid's Game 鍗氬紙 鍙栧瓙http://www.shnenglu.com/sdz/archive/2010/08/29/125124.html鑻ヤ綑鑻ヤ綑Sun, 29 Aug 2010 01:27:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/29/125124.htmlhttp://www.shnenglu.com/sdz/comments/125124.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/29/125124.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/125124.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/125124.htmlEuclid's Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4525 Accepted: 1849

Description

Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7):
         25 7

11 7
4 7
4 3
1 3
1 0

an Stan wins.

Input

The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.

Output

For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed.

Sample Input

34 12
15 24
0 0

Sample Output

Stan wins
Ollie wins

Source

Waterloo local 2002.09.28

緇欏畾涓ゅ爢鐭沖瓙,浜屼漢杞祦鍙栧瓙,瑕佹眰鍙兘浠庣煶瀛愭暟鐩緝澶х殑閭d竴鍫嗗彇瀛?鍙栧瓙鐨勬暟鐩彧鑳芥槸鍙︿竴鍫嗙煶瀛愭暟鐩殑鍊嶆暟.鏈緇堜嬌寰楁煇涓鍫嗘暟鐩負(fù)闆剁殑涓鏂逛負(fù)鑳?

棣栧厛,瀹規(guī)槗鐪嬪嚭,瀵逛簬姣忎竴涓眬闈?瑕佷箞鏄厛鎵嬪繀鑳?瑕佷箞鏄悗鎵嬪繀鑳?鏈緇堢粨鏋滃畬鍏ㄧ敱褰撳墠灞闈㈠畬鍏ㄧ‘瀹?

鍙﹀,鍙互綆鍗曠綏鍒椾竴涓嬪厛鎵嬪繀鑳滃拰蹇呰觸鐨勫嚑縐嶅眬闈?涓ゅ爢鐭沖瓙鍒濆鏁扮洰閮藉ぇ浜庨浂):

1,鏈変竴鍫嗙煶瀛愭暟鐩負(fù)涓,鍏堟墜蹇呰儨,聽 1,4,聽聽聽 1,2.
2,涓ゅ爢鐭沖瓙鏁扮洰宸竴,涓斾袱鍫嗙煶瀛愭暟鐩兘涓嶄負(fù)涓,鍏堟墜蹇呰觸(鍙兘浣垮悗鎵嬮潰瀵瑰繀鑳滅殑灞闈?,濡偮?3,4聽 5,6聽聽 .
3,濡傛灉鏁扮洰杈冨ぇ鐨勯偅涓鍫嗘槸鏁扮洰杈冨皬閭d竴鍫嗙殑2鍊嶅姞鍑忎竴,涓斾笉鏄笂闈袱縐嶅眬闈?鍏堟墜蹇呰儨,2,5聽 3,5聽 3,7.

鍙槸涓婇潰榪欎簺淇℃伅瀵逛簬瑙e喅榪欎釜闂榪樻槸鏈変竴浜涘洶闅?

鍐嶈繘涓姝ヨ瘯綆楁暟鐩緝?yōu)畯鐨勭煕_瓙,鍙互鍙戠幇,褰撲袱鍫嗘暟鐩浉宸緝澶ф椂,鎬繪槸鍏堟墜蹇呰儨.
浜嬪疄涓?榪涗竴姝ユ帰璁ㄥ彲浠ュ彂鐜頒笅闈㈢殑緇撹:

1,N<2*M-1鏃?鍏堟墜鍒棤閫夋嫨,鍙兘浣夸箣鍙樹負(fù) N-M,M 灞闈?(鏄撹)濡?,5聽 5,7聽 7,4...

2,璁句袱鍫嗙煶瀛愭暟鐩負(fù)N,M(N>M>0,涓擭,M浜掕川),鍒欒嫢N>=2*M-1,涓擭 - M ! =1鏃?鍏堟墜蹇呰儨.瑕佹眰M,N浜掕川鏄洜涓哄浜嶮,N鏈夊叕鍥犳暟鐨勬儏褰?鍙互鍚屾椂闄や互鍏跺叕鍥犳暟鑰屼笉褰卞搷緇撴灉.

綆鍗曡鏄庝竴涓嬩笂闈㈢粨璁?鐨勭敱鏉? N>=2*M-1鏃?鍏堟墜鍙嬌涔嬪彉涓郝?N%M,M聽 鎴朜%M+M,M涓ょ灞闈箣涓,鍏朵腑鏈変笖鍙湁涓涓繀璐ュ眬闈€傛敞鎰忓埌濡傛灉N%M,M涓嶆槸蹇呰觸灞闈紝閭d箞N%M+M,M灝辨槸蹇呰觸灞闈紝鍥犱負(fù)闈㈠N%M+M,M榪欎釜灞闈紝浣犲埆鏃犻夋嫨錛屽彧鑳藉湪鍓嶄竴鍫嗕腑鍙朚涓嬌瀵規(guī)柟闈㈠蹇呰儨灞闈?緇撹1 )銆?br />

鎹鍙璁$畻娉曞涓?
1.M,N鍏堝悓鏃墮櫎浠ュ畠浠殑鏈澶у叕鍥犳暟.(M<N)
2,濡傛灉M==0,鍒欒繑鍥為浂;
3,濡傛灉M==1,鍒欒繑鍥炰竴;
4,濡傛灉N>=M*2-1,鍒欒繑鍥炰竴
5,浠=M,M=N-M,閫掑綊澶勭悊

#include聽<iostream>
usingnamespace聽std;
longlong聽gcd(longlong聽a,longlong聽b)
{
聽聽聽聽
if(a==0)
聽聽聽聽聽聽聽聽
return聽b;
聽聽聽聽
return聽gcd(b%a,a);
}

longlong聽Eu(longlong聽m,longlong聽n)
{
聽聽聽聽
if(m==1)
聽聽聽聽聽聽聽聽
return1;
聽聽聽聽
if(n-m==1&&聽m)
聽聽聽聽聽聽聽聽
return0;
聽聽聽聽
if(n>=m*2-1)
聽聽聽聽聽聽聽聽
return1;
聽聽聽聽
return!Eu(n%m,m);
}


int聽聽main()
{
聽聽聽聽
longlong聽m,n,temp;
聽聽聽聽
while聽(cin>>m>>n聽&&聽(m||n))
聽聽聽聽
{
聽聽聽聽聽聽聽聽
longlong聽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;
聽聽聽聽}

聽聽聽聽
聽聽聽聽
return0;
}






鑻ヤ綑 2010-08-29 09:27 鍙戣〃璇勮
]]>
Poj 2153 Rank List --map / 璁℃暟鎺掑簭http://www.shnenglu.com/sdz/archive/2010/08/28/125050.html鑻ヤ綑鑻ヤ綑Sat, 28 Aug 2010 07:10:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/28/125050.htmlhttp://www.shnenglu.com/sdz/comments/125050.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/28/125050.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/125050.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/125050.htmlRank List
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 6561 Accepted: 2091

Description

Li Ming is a good student. He always asks the teacher about his rank in his class after every exam, which makes the teacher very tired. So the teacher gives him the scores of all the student in his class and asked him to get his rank by himself. However, he has so many classmates, and he can鈥檛 know his rank easily. So he tends to you for help, can you help him?

Input

The first line of the input contains an integer N (1 <= N <= 10000), which represents the number of student in Li Ming鈥檚 class. Then come N lines. Each line contains a name, which has no more than 30 letters. These names represent all the students in Li Ming鈥檚 class and you can assume that the names are different from each other.

In (N+2)-th line, you'll get an integer M (1 <= M <= 50), which represents the number of exams. The following M parts each represent an exam. Each exam has N lines. In each line, there is a positive integer S, which is no more then 100, and a name P, which must occur in the name list described above. It means that in this exam student P gains S scores. It鈥檚 confirmed that all the names in the name list will appear in an exam.

Output

The output contains M lines. In the i-th line, you should give the rank of Li Ming after the i-th exam. The rank is decided by the total scores. If Li Ming has the same score with others, he will always in front of others in the rank list.

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

POJ Monthly,Li Haoyuan

緇欏畾姣忎釜浜虹殑鎴愮嘩錛屾煡璇㈡煇涓浜虹殑鍚嶆銆?br />
鐢∕AP寤虹珛浜哄悕鍜屾垚緇╃殑瀵瑰簲鍏崇郴錛岀敤cnt鏁扮粍錛堟渶澶?000涓厓绱狅級璁板綍鎴愮嘩涓烘煇涓垎鏁扮殑浜烘暟錛屼笉榪囩敱浜庢諱漢鏁拌緝?yōu)?鏈澶氬彧鏈?0000浜?,鐩存帴閬嶅巻涔熶笉姣斿緩绔嬭鏁版帓搴忔暟緇勫鐢ㄥ灝戞椂闂?璁℃暟鎺掑簭鐨勪紭鍔垮茍涓嶆樉钁?

鐢╤ash鍑芥暟鎴栬呬簩鍒嗘煡鎵句篃搴旇鑳借В鍐寵繖涓棶棰?

/*Source聽Code

Problem:聽2153聽聽User:聽y09
Memory:聽1236K聽聽Time:聽1204MS聽
Language:聽C++聽聽Result:聽Accepted聽

Source聽Code聽
*/

#include聽
<iostream>
#include
<string>
#include
<map>
usingnamespace聽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);
聽聽聽聽}

聽聽聽聽
return0;
}




鑻ヤ綑 2010-08-28 15:10 鍙戣〃璇勮
]]>
1430 Binary Stirling Numbers 鏂壒鐏墊暟 http://www.shnenglu.com/sdz/archive/2010/08/28/125004.html鑻ヤ綑鑻ヤ綑Sat, 28 Aug 2010 00:51:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/28/125004.htmlhttp://www.shnenglu.com/sdz/comments/125004.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/28/125004.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/125004.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/125004.htmlBinary Stirling Numbers
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 1040 Accepted: 346

Description

The Stirling number of the second kind S(n, m) stands for the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:

{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}.


There is a recurrence which allows to compute S(n, m) for all m and n.

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.


Your task is much "easier". Given integers n and m satisfying 1 <= m <= n, compute the parity of S(n, m), i.e. S(n, m) mod 2.


Example

S(4, 2) mod 2 = 1.


Task

Write a program which for each data set:
reads two positive integers n and m,
computes S(n, m) mod 2,
writes the result.

Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 200. The data sets follow.

Line i + 1 contains the i-th data set - exactly two integers ni and mi separated by a single space, 1 <= mi <= ni <= 10^9.

Output

The output should consist of exactly d lines, one line for each data set. Line i, 1 <= i <= d, should contain 0 or 1, the value of S(ni, mi) mod 2.

Sample Input

1
4 2

Sample Output

1

Source


鍒ゆ柇絎簩綾繪柉鐗圭伒鏁版ā 2 鐨勪綑鏁般?br>
鍦ㄥ垬姹濅匠鐨勯粦涔︿笂鏈夎緇嗚В絳旓紝鍩烘湰鎬濊礬鏄灇涓炬暟鍊艱緝?yōu)畯鐨勬柉鐗圭亯|暟錛屼粠涓鎵捐寰嬨?br>
涓嬮潰榪欏箙鍥炬槸浠庣淮鍩虹櫨縐戞埅鍑烘潵鐨勶紝鏈変竴涓簩榪涘埗鏂壒鐏墊暟涓庣粍鍚堟暟鐨勮漿鍖栧叕寮忋傝岀粍鍚堟暟妯′簩鐨勪綑鏁板氨寰堝鏄撲簡銆?br>
鎴戜滑鐭ラ亾錛岀粍鍚堟暟C錛圢,M錛?N ! / M ! /(N-M)!,鍥犺屽彧闇姹傚緱闃朵箻璐ㄥ洜鏁板垎瑙e紡涓簩鐨勯噸鏁板嵆鍙В鍐抽棶棰樸?br>鑰孨 錛佽川鍥犳暟鍒嗚В鍚?鐨勯噸鏁板彲鐢ㄤ笅寮忔潵璁$畻涔嬨?br>K=N/2+N/2^2+N/2^3+....
涓婂紡鐨勯櫎娉曞叏鏄笅鍙栨暣銆傦紙鍙弬瑙佷換浣曚竴鏈垵絳夋暟璁鴻鏈紝濡傚寳澶ф綐鎵挎礊緙栫殑閭f湰銆婂垵絳夋暟璁恒嬶級銆?br>
榪欐牱錛岃繖涓棶棰樺氨榪庡垉鑰岃В銆?br>
鍙﹀錛屾湁涓鐐硅鏄庣殑鏄笂闈㈤偅涓浘褰紝灝辨槸鍒嗗艦鍑犱綍涓竴涓緢閲嶈鐨勪緥瀛愨斺旇阿褰柉鍩哄灚鐗囥傛潹杈変笁瑙掍篃鏈夌被浼肩殑褰㈢姸銆?br>榪欐槸鎴戠敤MATLAB浣滅殑涓涓潹杈変笁瑙掔殑浜岃繘鍒跺浘褰€?br>
#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;
}





鑻ヤ綑 2010-08-28 08:51 鍙戣〃璇勮
]]>
POJ 3318 Matrix Multiplication 闅忔満鍖栫畻娉?/title><link>http://www.shnenglu.com/sdz/archive/2010/08/27/124959.html</link><dc:creator>鑻ヤ綑</dc:creator><author>鑻ヤ綑</author><pubDate>Fri, 27 Aug 2010 10:20:00 GMT</pubDate><guid>http://www.shnenglu.com/sdz/archive/2010/08/27/124959.html</guid><wfw:comment>http://www.shnenglu.com/sdz/comments/124959.html</wfw:comment><comments>http://www.shnenglu.com/sdz/archive/2010/08/27/124959.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/sdz/comments/commentRss/124959.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/sdz/services/trackbacks/124959.html</trackback:ping><description><![CDATA[<div id="pjdpzhf" class=ptt lang=zh-CN>Matrix Multiplication</div> <div id="xzlnpxn" class=plm> <table align=center> <tbody> <tr> <td><strong>Time Limit:</strong> 2000MS</td> <td width=10></td> <td><strong>Memory Limit:</strong> 65536K</td> </tr> <tr> <td><strong>Total Submissions:</strong> 11924</td> <td width=10></td> <td><strong>Accepted:</strong> 2408</td> </tr> </tbody> </table> </div> <p class=pst>Description</p> <div id="rbdpzxv" class=ptx lang=zh-CN> <p>You are given three <em>n</em> × <em>n</em> matrices <em>A</em>, <em>B</em> and <em>C</em>. Does the equation <em>A</em> × <em>B</em> = <em>C</em> hold true?</p> </div> <p class=pst>Input</p> <div id="ldpztrz" class=ptx lang=zh-CN> <p>The first line of input contains a positive integer <em>n</em> (<em>n</em> ≤ 500) followed by the the three matrices <em>A</em>, <em>B</em> and <em>C </em>respectively. Each matrix's description is a block of n × n integers.</p> <p>It guarantees that the elements of <em>A</em> and <em>B</em> are less than 100 in absolute value and elements of <em>C</em> are less than 10,000,000 in absolute value.</p> </div> <p class=pst>Output</p> <div id="rlfrdbr" class=ptx lang=zh-CN> <p>Output "YES" if the equation holds true, otherwise "NO".</p> </div> <p class=pst>Sample Input</p> <pre class=sio>2 1 0 2 3 5 1 0 8 5 1 10 26 </pre> <p class=pst>Sample Output</p> <pre class=sio>YES</pre> <p class=pst>Hint</p> <div id="rlffhpv" class=ptx lang=zh-CN>Multiple inputs will be tested. So O(n<sup>3</sup>) algorithm will get TLE.</div> <p class=pst>Source<br><br></p> 緇欏畾鐭╅樀A(chǔ)鍜孊錛屽垽鏂煩闃礐鏄笉鏄畠浠殑涔樼Н銆?br><br>棰樼洰鏄庣‘琛ㄧず鐩存帴鍒ゆ柇浼?xì)瓒呮椨灱岃孲trass鍜岀洿鎺ョ浉涔樼殑O錛坣^3錛夋晥鏋滅浉宸笉澶氥?br>鍥犺岄噰鐢ㄩ殢鏈哄寲鏂規(guī)硶錛屾寜鎴戣嚜宸辯殑鎯蟲硶錛岄殢鏈烘祴璇旵涓殑鑻ュ共鍏冪礌錛屼互紜畾緇撴灉錛岀湅浜嗚璁哄尯錛屾墠鍙戠幇鏈夋洿鍔?#8220;涓撲笟”鐨勫姙娉曘?br>闅忔満鐢熸垚琛屽悜閲廔錛屽垯鑻*B=C錛岄偅涔堝繀鏈塈*A*B=I*C錛涘弽涔嬶紝涓嶄竴瀹氭垚绔嬶紝綆楁硶鐨勯殢鏈烘ф浣撶幇鍦ㄨ繖閲屻?br>鐢ㄤ竴涓繀瑕佷笉鍏呭垎鏉′歡鏉ュ垽鏂粨鏋滅殑姝g‘鎬э紝姣旂洸鐩祴璇曟晥鏋滃線寰瑕佸ソ寰楀銆?br>榪欎釜蹇呰鏉′歡鍒ゆ柇緇撴灉鐨勬椂闂村鏉傚害鏄疧錛圢^2錛夌殑錛岃繖鏄鐩緭鍏ユ暟鎹噺鍙互鎺ュ彈鐨勩?br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Codehighlighter1_0_115_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_115_Open_Text.style.display='none'; Codehighlighter1_0_115_Closed_Image.style.display='inline'; Codehighlighter1_0_115_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_0_115_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_115_Closed_Text.style.display='none'; Codehighlighter1_0_115_Open_Image.style.display='inline'; Codehighlighter1_0_115_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><span id=Codehighlighter1_0_115_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_0_115_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">Source Code<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Problem: 3318  User: y09 <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Memory: 3080K  Time: 1063MS <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Language: C  Result: Accepted <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>Source Code </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">time.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdlib.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_184_953_Open_Image onclick="this.style.display='none'; Codehighlighter1_184_953_Open_Text.style.display='none'; Codehighlighter1_184_953_Closed_Image.style.display='inline'; Codehighlighter1_184_953_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_184_953_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_184_953_Closed_Text.style.display='none'; Codehighlighter1_184_953_Open_Image.style.display='inline'; Codehighlighter1_184_953_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_184_953_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_184_953_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,j;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mat1[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mat2[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mat3[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">];<br><img id=Codehighlighter1_285_287_Open_Image onclick="this.style.display='none'; Codehighlighter1_285_287_Open_Text.style.display='none'; Codehighlighter1_285_287_Closed_Image.style.display='inline'; Codehighlighter1_285_287_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_285_287_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_285_287_Closed_Text.style.display='none'; Codehighlighter1_285_287_Open_Image.style.display='inline'; Codehighlighter1_285_287_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    __int64 te1[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_285_287_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_285_287_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_308_310_Open_Image onclick="this.style.display='none'; Codehighlighter1_308_310_Open_Text.style.display='none'; Codehighlighter1_308_310_Closed_Image.style.display='inline'; Codehighlighter1_308_310_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_308_310_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_308_310_Closed_Text.style.display='none'; Codehighlighter1_308_310_Open_Image.style.display='inline'; Codehighlighter1_308_310_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    __int64 te2[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_308_310_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_308_310_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_331_333_Open_Image onclick="this.style.display='none'; Codehighlighter1_331_333_Open_Text.style.display='none'; Codehighlighter1_331_333_Closed_Image.style.display='inline'; Codehighlighter1_331_333_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_331_333_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_331_333_Closed_Text.style.display='none'; Codehighlighter1_331_333_Open_Image.style.display='inline'; Codehighlighter1_331_333_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    __int64 te3[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_331_333_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_331_333_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img id=Codehighlighter1_354_356_Open_Image onclick="this.style.display='none'; Codehighlighter1_354_356_Open_Text.style.display='none'; Codehighlighter1_354_356_Closed_Image.style.display='inline'; Codehighlighter1_354_356_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_354_356_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_354_356_Closed_Text.style.display='none'; Codehighlighter1_354_356_Open_Image.style.display='inline'; Codehighlighter1_354_356_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    __int64 te4[</span><span style="COLOR: #000000">500</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span id=Codehighlighter1_354_356_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_354_356_Open_Text><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">}</span></span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    time_t t;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    srand((unsigned) time(</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">t));<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">n);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">mat1[i][j]);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">mat2[i][j]);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">mat3[i][j]);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        te1[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">rand()</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            te2[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">te1[j]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">mat1[j][i];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            te3[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">te2[j]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">mat2[j][i];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            te4[i]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">te1[j]</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">mat3[j][i];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(te3[i]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">te4[i])<br><img id=Codehighlighter1_892_924_Open_Image onclick="this.style.display='none'; Codehighlighter1_892_924_Open_Text.style.display='none'; Codehighlighter1_892_924_Closed_Image.style.display='inline'; Codehighlighter1_892_924_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_892_924_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_892_924_Closed_Text.style.display='none'; Codehighlighter1_892_924_Open_Image.style.display='inline'; Codehighlighter1_892_924_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_892_924_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_892_924_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            puts(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NO</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    puts(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">YES</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <br><br> <img src ="http://www.shnenglu.com/sdz/aggbug/124959.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/sdz/" target="_blank">鑻ヤ綑</a> 2010-08-27 18:20 <a href="http://www.shnenglu.com/sdz/archive/2010/08/27/124959.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 1195 Mobile phones 浜岀淮鏍?wèi)鐘舵暟缁?/title><link>http://www.shnenglu.com/sdz/archive/2010/08/27/124949.html</link><dc:creator>鑻ヤ綑</dc:creator><author>鑻ヤ綑</author><pubDate>Fri, 27 Aug 2010 08:28:00 GMT</pubDate><guid>http://www.shnenglu.com/sdz/archive/2010/08/27/124949.html</guid><wfw:comment>http://www.shnenglu.com/sdz/comments/124949.html</wfw:comment><comments>http://www.shnenglu.com/sdz/archive/2010/08/27/124949.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/sdz/comments/commentRss/124949.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/sdz/services/trackbacks/124949.html</trackback:ping><description><![CDATA[<div id="tvztnlr" class=ptt lang=zh-CN>Mobile phones</div> <div id="nnzjllz" class=plm> <table align=center> <tbody> <tr> <td><strong>Time Limit:</strong> 5000MS</td> <td width=10></td> <td><strong>Memory Limit:</strong> 65536K</td> </tr> <tr> <td><strong>Total Submissions:</strong> 7087</td> <td width=10></td> <td><strong>Accepted:</strong> 3030</td> </tr> </tbody> </table> </div> <p class=pst>Description</p> <div id="dhjtfdb" class=ptx lang=zh-CN>Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbered from 0 to S-1. Each square contains a base station. The number of active mobile phones inside a square can change because a phone is moved from a square to another or a phone is switched on or off. At times, each base station reports the change in the number of active phones to the main base station along with the row and the column of the matrix. <br><br>Write a program, which receives these reports and answers queries about the current total number of active mobile phones in any rectangle-shaped area. <br></div> <p class=pst>Input</p> <div id="lnhbbbz" class=ptx lang=zh-CN>The input is read from standard input as integers and the answers to the queries are written to standard output as integers. The input is encoded as follows. Each input comes on a separate line, and consists of one instruction integer and a number of parameter integers according to the following table. <br> <center><img src="http://acm.pku.edu.cn/JudgeOnline/images/1195_1.jpg"></center><br>The values will always be in range, so there is no need to check them. In particular, if A is negative, it can be assumed that it will not reduce the square value below zero. The indexing starts at 0, e.g. for a table of size 4 * 4, we have 0 <= X <= 3 and 0 <= Y <= 3. <br><br>Table size: 1 * 1 <= S * S <= 1024 * 1024 <br>Cell value V at any time: 0 <= V <= 32767 <br>Update amount: -32768 <= A <= 32767 <br>No of instructions in input: 3 <= U <= 60002 <br>Maximum number of phones in the whole table: M= 2^30 <br></div> <p class=pst>Output</p> <div id="bnhzbhz" class=ptx lang=zh-CN>Your program should not answer anything to lines with an instruction other than 2. If the instruction is 2, then your program is expected to answer the query by writing the answer as a single line containing a single integer to standard output. </div> <p class=pst>Sample Input</p> <pre class=sio>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 </pre> <p class=pst>Sample Output</p> <pre class=sio>3 4</pre> <p class=pst>Source</p> <div id="zbtpzhx" class=ptx lang=zh-CN><a ><u><font color=#0000ff>IOI 2001</font></u></a><br><br></div> <br>涓緇存爲(wèi)鐘舵暟緇勭敤涓緇存暟緇勬潵瀛樺偍閮ㄥ垎鍏冪礌鐨勫拰錛屼簩緇存爲(wèi)鐘舵暟緇勫彧闇鐢ㄤ簩緇存暟緇勬潵瀛樺偍鍗沖彲錛岃幏寰楀拰錛屼慨姝g殑鍑芥暟鍚屼竴緇存暟緇勫樊鍒笉澶с?br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Codehighlighter1_0_116_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_116_Open_Text.style.display='none'; Codehighlighter1_0_116_Closed_Image.style.display='inline'; Codehighlighter1_0_116_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_0_116_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_116_Closed_Text.style.display='none'; Codehighlighter1_0_116_Open_Image.style.display='inline'; Codehighlighter1_0_116_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><span id=Codehighlighter1_0_116_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_0_116_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">Source Code<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Problem: 1195  User: y09 <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Memory: 4956K  Time: 579MS <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Language: C++  Result: Accepted <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>Source Code </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1200</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> c[MAX][MAX];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> LowBit(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> t)<br><img id=Codehighlighter1_199_222_Open_Image onclick="this.style.display='none'; Codehighlighter1_199_222_Open_Text.style.display='none'; Codehighlighter1_199_222_Closed_Image.style.display='inline'; Codehighlighter1_199_222_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_199_222_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_199_222_Closed_Text.style.display='none'; Codehighlighter1_199_222_Open_Image.style.display='inline'; Codehighlighter1_199_222_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_199_222_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_199_222_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> t</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">^</span><span style="COLOR: #000000">(t</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Sum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> endx,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> endy)<br><img id=Codehighlighter1_252_452_Open_Image onclick="this.style.display='none'; Codehighlighter1_252_452_Open_Text.style.display='none'; Codehighlighter1_252_452_Closed_Image.style.display='inline'; Codehighlighter1_252_452_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_252_452_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_252_452_Closed_Text.style.display='none'; Codehighlighter1_252_452_Open_Image.style.display='inline'; Codehighlighter1_252_452_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_252_452_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_252_452_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">endy;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(endx</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_298_437_Open_Image onclick="this.style.display='none'; Codehighlighter1_298_437_Open_Text.style.display='none'; Codehighlighter1_298_437_Closed_Image.style.display='inline'; Codehighlighter1_298_437_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_298_437_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_298_437_Closed_Text.style.display='none'; Codehighlighter1_298_437_Open_Image.style.display='inline'; Codehighlighter1_298_437_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_298_437_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_298_437_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        endy</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">娉ㄦ剰璁板綍endy鐨勫鹼紝鏈漢鍦ㄦ鍑洪敊錛屾壘鍗婂ぉ閿欒涓嶅緱</span><span style="COLOR: #008000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (endy</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_359_409_Open_Image onclick="this.style.display='none'; Codehighlighter1_359_409_Open_Text.style.display='none'; Codehighlighter1_359_409_Closed_Image.style.display='inline'; Codehighlighter1_359_409_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_359_409_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_359_409_Closed_Text.style.display='none'; Codehighlighter1_359_409_Open_Image.style.display='inline'; Codehighlighter1_359_409_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_359_409_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_359_409_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            sum</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">c[endx][endy];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            endy</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">LowBit(endy);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        endx</span><span style="COLOR: #000000">-=</span><span style="COLOR: #000000">LowBit(endx);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> sum;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> plus(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> posx,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> posy,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> num)<br><img id=Codehighlighter1_491_639_Open_Image onclick="this.style.display='none'; Codehighlighter1_491_639_Open_Text.style.display='none'; Codehighlighter1_491_639_Closed_Image.style.display='inline'; Codehighlighter1_491_639_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_491_639_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_491_639_Closed_Text.style.display='none'; Codehighlighter1_491_639_Open_Image.style.display='inline'; Codehighlighter1_491_639_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_491_639_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_491_639_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">posy;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (posx </span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n)<br><img id=Codehighlighter1_528_637_Open_Image onclick="this.style.display='none'; Codehighlighter1_528_637_Open_Text.style.display='none'; Codehighlighter1_528_637_Closed_Image.style.display='inline'; Codehighlighter1_528_637_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_528_637_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_528_637_Closed_Text.style.display='none'; Codehighlighter1_528_637_Open_Image.style.display='inline'; Codehighlighter1_528_637_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_528_637_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_528_637_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        posy</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(posy</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n)<br><img id=Codehighlighter1_562_612_Open_Image onclick="this.style.display='none'; Codehighlighter1_562_612_Open_Text.style.display='none'; Codehighlighter1_562_612_Closed_Image.style.display='inline'; Codehighlighter1_562_612_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_562_612_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_562_612_Closed_Text.style.display='none'; Codehighlighter1_562_612_Open_Image.style.display='inline'; Codehighlighter1_562_612_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_562_612_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_562_612_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            c[posx][posy]</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">num;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            posy</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">LowBit(posy);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        posx</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">LowBit(posx);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> GetSum(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> b,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> r,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> t)<br><img id=Codehighlighter1_677_732_Open_Image onclick="this.style.display='none'; Codehighlighter1_677_732_Open_Text.style.display='none'; Codehighlighter1_677_732_Closed_Image.style.display='inline'; Codehighlighter1_677_732_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_677_732_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_677_732_Closed_Text.style.display='none'; Codehighlighter1_677_732_Open_Image.style.display='inline'; Codehighlighter1_677_732_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_677_732_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_677_732_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> Sum(r,t)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Sum(r,b</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">Sum(l</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,t)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">Sum(l</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,b</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_745_1077_Open_Image onclick="this.style.display='none'; Codehighlighter1_745_1077_Open_Text.style.display='none'; Codehighlighter1_745_1077_Closed_Image.style.display='inline'; Codehighlighter1_745_1077_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_745_1077_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_745_1077_Closed_Text.style.display='none'; Codehighlighter1_745_1077_Open_Image.style.display='inline'; Codehighlighter1_745_1077_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_745_1077_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_745_1077_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> I;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> x,y,a;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l,b,r,t;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">I))<br><img id=Codehighlighter1_805_1062_Open_Image onclick="this.style.display='none'; Codehighlighter1_805_1062_Open_Text.style.display='none'; Codehighlighter1_805_1062_Closed_Image.style.display='inline'; Codehighlighter1_805_1062_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_805_1062_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_805_1062_Closed_Text.style.display='none'; Codehighlighter1_805_1062_Open_Image.style.display='inline'; Codehighlighter1_805_1062_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_805_1062_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_805_1062_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000"> (I)<br><img id=Codehighlighter1_822_1059_Open_Image onclick="this.style.display='none'; Codehighlighter1_822_1059_Open_Text.style.display='none'; Codehighlighter1_822_1059_Closed_Image.style.display='inline'; Codehighlighter1_822_1059_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_822_1059_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_822_1059_Closed_Text.style.display='none'; Codehighlighter1_822_1059_Open_Image.style.display='inline'; Codehighlighter1_822_1059_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>        </span><span id=Codehighlighter1_822_1059_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_822_1059_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">:<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">n);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">x,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">y,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">a);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            plus(x</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,y</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,a);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">:<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">l,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">b,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">r,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">t);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,GetSum(l</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,b</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,r</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,t</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">));<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">:<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>            <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>        }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span></div> <img src ="http://www.shnenglu.com/sdz/aggbug/124949.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/sdz/" target="_blank">鑻ヤ綑</a> 2010-08-27 16:28 <a href="http://www.shnenglu.com/sdz/archive/2010/08/27/124949.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>POJ 1026 Cipherhttp://www.shnenglu.com/sdz/archive/2010/08/25/124625.html鑻ヤ綑鑻ヤ綑Wed, 25 Aug 2010 01:29:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/25/124625.htmlhttp://www.shnenglu.com/sdz/comments/124625.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/25/124625.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/124625.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/124625.htmlCipher
Time Limit: 1000MS  Memory Limit: 10000K
Total Submissions: 12776  Accepted: 3194


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)
    
{
        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;
}



鑻ヤ綑 2010-08-25 09:29 鍙戣〃璇勮
]]>
Poj 2785 4 Values whose Sum is 0 hash 鍝堝笇琛?/title><link>http://www.shnenglu.com/sdz/archive/2010/08/23/124349.html</link><dc:creator>鑻ヤ綑</dc:creator><author>鑻ヤ綑</author><pubDate>Mon, 23 Aug 2010 00:23:00 GMT</pubDate><guid>http://www.shnenglu.com/sdz/archive/2010/08/23/124349.html</guid><wfw:comment>http://www.shnenglu.com/sdz/comments/124349.html</wfw:comment><comments>http://www.shnenglu.com/sdz/archive/2010/08/23/124349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/sdz/comments/commentRss/124349.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/sdz/services/trackbacks/124349.html</trackback:ping><description><![CDATA[<p>棰樻剰綆鍗?灝辨槸鎵懼洓涓暟鐨勫拰涓洪浂.鍏堟妸鍓嶄袱鍒楃殑鍜岀畻鍑烘潵,O(n^2),瀛樺埌hash琛ㄤ腑,鍐嶆妸鍚庝袱鍒楃殑涓や袱鍜岀畻鍑烘潵,鍦╤ash琛ㄤ腑鎵劇浉鍙嶆暟.鐢ㄧ嚎鎬ф帰嫻嬫硶灝卞彲浠ヨВ鍐寵闂浜?<br></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img id=Codehighlighter1_0_122_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_122_Open_Text.style.display='none'; Codehighlighter1_0_122_Closed_Image.style.display='inline'; Codehighlighter1_0_122_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_0_122_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_122_Closed_Text.style.display='none'; Codehighlighter1_0_122_Open_Image.style.display='inline'; Codehighlighter1_0_122_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top><span id=Codehighlighter1_0_122_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id=Codehighlighter1_0_122_Open_Text><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">Source CodeProblem: 2785        User: y09shendazhi<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Memory: 160132K        Time: 2610MS<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>Language: G++        Result: Accepted<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>Source Code</span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include </span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">stdio.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> size</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">20345677</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> hash[size];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum[size];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> key</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1777</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> MAX</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1000000000</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Insert(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> num)<br><img id=Codehighlighter1_307_440_Open_Image onclick="this.style.display='none'; Codehighlighter1_307_440_Open_Text.style.display='none'; Codehighlighter1_307_440_Closed_Image.style.display='inline'; Codehighlighter1_307_440_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_307_440_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_307_440_Closed_Text.style.display='none'; Codehighlighter1_307_440_Open_Image.style.display='inline'; Codehighlighter1_307_440_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_307_440_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_307_440_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(num</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">MAX)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">size;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(hash[num]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">MAX </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> hash[num]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">temp)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(key</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">num)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">size;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    hash[num]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    sum[num]</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> Find(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> num)<br><img id=Codehighlighter1_460_619_Open_Image onclick="this.style.display='none'; Codehighlighter1_460_619_Open_Text.style.display='none'; Codehighlighter1_460_619_Closed_Image.style.display='inline'; Codehighlighter1_460_619_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_460_619_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_460_619_Closed_Text.style.display='none'; Codehighlighter1_460_619_Open_Image.style.display='inline'; Codehighlighter1_460_619_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_460_619_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_460_619_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">num;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(num</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">MAX)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">size;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(hash[num]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">MAX </span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000"> hash[num]</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">temp)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        num</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">(num</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">key)</span><span style="COLOR: #000000">%</span><span style="COLOR: #000000">size;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(hash[num]</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">MAX)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> sum[num];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br><img id=Codehighlighter1_633_1003_Open_Image onclick="this.style.display='none'; Codehighlighter1_633_1003_Open_Text.style.display='none'; Codehighlighter1_633_1003_Closed_Image.style.display='inline'; Codehighlighter1_633_1003_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_633_1003_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_633_1003_Closed_Text.style.display='none'; Codehighlighter1_633_1003_Open_Image.style.display='inline'; Codehighlighter1_633_1003_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_633_1003_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_633_1003_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i,j;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a[</span><span style="COLOR: #000000">4005</span><span style="COLOR: #000000">],b[</span><span style="COLOR: #000000">4005</span><span style="COLOR: #000000">],c[</span><span style="COLOR: #000000">4005</span><span style="COLOR: #000000">],d[</span><span style="COLOR: #000000">4005</span><span style="COLOR: #000000">];<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">n);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> ans</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_740_788_Open_Image onclick="this.style.display='none'; Codehighlighter1_740_788_Open_Text.style.display='none'; Codehighlighter1_740_788_Closed_Image.style.display='inline'; Codehighlighter1_740_788_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_740_788_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_740_788_Closed_Text.style.display='none'; Codehighlighter1_740_788_Open_Image.style.display='inline'; Codehighlighter1_740_788_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_740_788_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_740_788_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        scanf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d%d%d%d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">a[i],</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">b[i],</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">c[i],</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">d[i]);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">size;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_812_830_Open_Image onclick="this.style.display='none'; Codehighlighter1_812_830_Open_Text.style.display='none'; Codehighlighter1_812_830_Closed_Image.style.display='inline'; Codehighlighter1_812_830_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_812_830_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_812_830_Closed_Text.style.display='none'; Codehighlighter1_812_830_Open_Image.style.display='inline'; Codehighlighter1_812_830_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_812_830_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_812_830_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        hash[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">MAX;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_870_894_Open_Image onclick="this.style.display='none'; Codehighlighter1_870_894_Open_Text.style.display='none'; Codehighlighter1_870_894_Closed_Image.style.display='inline'; Codehighlighter1_870_894_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_870_894_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_870_894_Closed_Text.style.display='none'; Codehighlighter1_870_894_Open_Image.style.display='inline'; Codehighlighter1_870_894_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_870_894_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_870_894_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        Insert(a[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">b[j]);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">n;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_934_964_Open_Image onclick="this.style.display='none'; Codehighlighter1_934_964_Open_Text.style.display='none'; Codehighlighter1_934_964_Closed_Image.style.display='inline'; Codehighlighter1_934_964_Closed_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_934_964_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_934_964_Closed_Text.style.display='none'; Codehighlighter1_934_964_Open_Image.style.display='inline'; Codehighlighter1_934_964_Open_Text.style.display='inline';" src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>    </span><span id=Codehighlighter1_934_964_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_934_964_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>        ans</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">Find(</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">(c[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">d[j]));<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>    }</span></span><span style="COLOR: #000000"><br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    printf(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%d\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,ans);<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    <br><img src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif" align=top>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span></div> <img src ="http://www.shnenglu.com/sdz/aggbug/124349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/sdz/" target="_blank">鑻ヤ綑</a> 2010-08-23 08:23 <a href="http://www.shnenglu.com/sdz/archive/2010/08/23/124349.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Push Botton Lock poj 3088鏂壒鐏墊暟http://www.shnenglu.com/sdz/archive/2010/08/21/124202.html鑻ヤ綑鑻ヤ綑Sat, 21 Aug 2010 10:20:00 GMThttp://www.shnenglu.com/sdz/archive/2010/08/21/124202.htmlhttp://www.shnenglu.com/sdz/comments/124202.htmlhttp://www.shnenglu.com/sdz/archive/2010/08/21/124202.html#Feedback0http://www.shnenglu.com/sdz/comments/commentRss/124202.htmlhttp://www.shnenglu.com/sdz/services/trackbacks/124202.html
/*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;
}


鑻ヤ綑 2010-08-21 18:20 鍙戣〃璇勮
]]>
无码人妻精品一区二区三区久久久| 亚洲国产综合久久天堂| 午夜天堂av天堂久久久| 精品综合久久久久久888蜜芽| 精品久久久久久无码中文字幕一区 | 成人国内精品久久久久一区| 久久精品国产亚洲AV高清热 | 99久久综合国产精品二区| 青青热久久综合网伊人| 久久经典免费视频| 四虎国产精品免费久久5151| 亚洲va久久久久| 久久综合欧美成人| 久久热这里只有精品在线观看| 久久国产精品久久国产精品| 中文字幕无码久久人妻| 伊人久久大香线蕉影院95| 亚洲精品乱码久久久久久久久久久久| 婷婷综合久久中文字幕| 无码国内精品久久人妻| 久久影院午夜理论片无码| 国产精品久久永久免费| 久久无码高潮喷水| 久久青青国产| 日韩欧美亚洲综合久久影院d3| 久久婷婷五月综合97色一本一本| 久久影院亚洲一区| 国产精品免费看久久久香蕉| 久久99国产精品尤物| 国产成人精品三上悠亚久久| 深夜久久AAAAA级毛片免费看| 国产福利电影一区二区三区久久老子无码午夜伦不| 欧美久久一区二区三区| 欧洲性大片xxxxx久久久| 精品99久久aaa一级毛片| 久久精品国产亚洲网站| 久久99国产精品久久99| 国产精品一久久香蕉产线看| 国产精品久久久久9999| 72种姿势欧美久久久久大黄蕉| 久久精品国产亚洲av水果派|