锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Farmer Brown's cows are up in arms, having heard that McDonalds is
considering the introduction of a new product: Beef McNuggets. The
cows are trying to find any possible way to put such a product in a
negative light.
One strategy the cows are pursuing is that of `inferior packaging'.
``Look,'' say the cows, ``if you have Beef McNuggets in boxes of 3, 6,
and 10, you can not satisfy a customer who wants 1, 2, 4, 5, 7, 8, 11,
14, or 17 McNuggets. Bad packaging: bad product.''
Help the cows. Given N (the number of packaging options, 1 <= N
<= 10), and a set of N positive integers (1 <= i <= 256) that
represent the number of nuggets in the various packages, output the
largest number of nuggets that can not be purchased by buying nuggets
in the given sizes. Print 0 if all possible purchases can be made or
if there is no bound to the largest number.
The largest impossible number (if it exists) will be no larger than
2,000,000,000.
Consider an ordered set S of strings of N (1 <= N <= 31)
bits. Bits, of course, are either 0 or 1.
This set of strings is interesting because it is ordered and
contains all possible strings of length N that have L (1 <= L
<= N) or fewer bits that are `1'.
Your task is to read a number I (1 <= I <= sizeof(S))
from the input and print the Ith element of the ordered set for N
bits with no more than L bits that are `1'.
The factorial of an integer N, written N!, is the product of all
the integers from 1 through N inclusive. The factorial quickly becomes
very large: 13! is too large to store in a 32-bit integer on most
computers, and 70! is too large for most floating-point variables. Your
task is to find the rightmost non-zero digit of n!. For example, 5! =
1 * 2 * 3 * 4 * 5 = 120, so the rightmost non-zero digit of 5! is 2.
Likewise, 7! = 1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040, so the rightmost non-zero
digit of 7! is 4.
The cows have developed a new interest in scanning the universe
outside their farm with radiotelescopes. Recently, they noticed a very
curious microwave pulsing emission sent right from the centre of the
galaxy. They wish to know if the emission is transmitted by some
extraterrestrial form of intelligent life or if it is nothing but the
usual heartbeat of the stars.
Help the cows to find the Truth by providing a tool to analyze bit
patterns in the files they record. They are seeking bit patterns of
length A through B inclusive (1 <= A <= B <= 12)
that repeat themselves most often in each day's data file. They are
looking for the patterns that repeat themselves most often. An input
limit tells how many of the most frequent patterns to output.
Pattern occurrences may overlap, and only patterns that occur at
least once are taken into account.
In this example, pattern 100 occurs 12 times, and pattern 1000 occurs
5 times. The most frequent pattern is 00, with 23 occurrences.
Lines that list the N highest frequencies (in descending order of
frequency) along with the patterns that occur in those frequencies.
Order those patterns by shortest-to-longest and increasing binary number
for those of the same frequency. If fewer than N highest frequencies
are available, print only those that are.
Print the frequency alone by itself on a line. Then print the actual
patterns space separated, six to a line (unless fewer than six remain).
]]>
鐢╨ast璁板綍鏈灝忕殑鈥滀笉鑳界粍鎴愮殑鏁扳濄傝繖鏍峰綋last涔嬪悗鏈塨oxs[0]涓繛緇暟閮藉彲浠ョ粍鎴愮殑璇濓紝閭d箞鎵鏈夌殑鏁伴兘鍙互緇勬垚銆?br />last+1...last+box[0]鍙互緇勬垚鐨勮瘽錛岄偅涔堟瘡涓暟閮藉姞涓涓猙ox[0],閭d箞鏂頒竴杞殑box[0]涓暟涔熷彲浠ョ粍鎴愶紝浠ユ綾繪帹銆?br />
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("nuggets.in");
ofstream聽fout("nuggets.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽box_num;
int聽boxs[10];
bool聽ok[256];
int聽gcd(int聽a,int聽b)
{
聽聽聽聽if(a<b)聽swap(a,b);
聽聽聽聽int聽tmp;
聽聽聽聽while(b!=0){
聽聽聽聽聽聽聽聽tmp聽=聽a;
聽聽聽聽聽聽聽聽a聽=聽b;
聽聽聽聽聽聽聽聽b聽=聽tmp%b;
聽聽聽聽}
聽聽聽聽return聽a;
}
void聽solve()
{
聽聽聽聽in>>box_num;
聽聽聽聽for(int聽i=0;i<box_num;++i)
聽聽聽聽聽聽聽聽in>>boxs[i];
聽聽聽聽sort(&boxs[0],&boxs[box_num]);
聽聽聽聽
聽聽聽聽int聽t聽=聽boxs[0];
聽聽聽聽for(int聽i=1;i<box_num;++i){
聽聽聽聽聽聽聽聽t聽=聽gcd(t,boxs[i]);
聽聽聽聽}
聽聽聽聽if(t!=1){
聽聽聽聽聽聽聽聽out<<0<<endl;
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽聽memset(ok,0,sizeof(ok));
聽聽聽聽int聽last聽=聽0;
聽聽聽聽ok[0]聽=聽true;
聽聽聽聽int聽i=0;
聽聽聽聽while(true){
聽聽聽聽聽聽聽聽if(ok[i%256]){
聽聽聽聽聽聽聽聽聽聽聽聽ok[i%256]聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽if(i-last>=boxs[0]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<last<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽x=0;x<box_num;++x){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ok[(i+boxs[x])%256]聽=聽true;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽last聽=聽i;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽++i;
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
Hubert ChenPROGRAM NAME: nuggets
INPUT FORMAT
Line 1: N, the number of packaging options Line 2..N+1: The number of nuggets in one kind of
box SAMPLE INPUT (file nuggets.in)
3
3
6
10OUTPUT FORMAT
The output file should contain a single line containing a single integer
that represents the largest number of nuggets that can not be represented
or 0 if all possible purchases can be made or if there is no bound to
the largest number.
SAMPLE OUTPUT (file nuggets.out)
17
]]>
鏁版嵁閲忔瘮杈冨皯錛岀敤鍥炴函娉曪紝dp涔熻銆?br />
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("rockers.in");
ofstream聽fout("rockers.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽capacity[20];;
int聽songs[20];
int聽song_num,disk_num;
int聽res聽=聽0;
int聽cur;
void聽backtracing(int聽depth,int聽last)
{
聽聽聽聽if(depth==song_num){
聽聽聽聽聽聽聽聽if(cur>res){
聽聽聽聽聽聽聽聽聽聽聽聽res聽=聽cur;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽
聽聽聽 //濡傛灉鍚庨潰鎵鏈夌殑姝屾洸閮藉姞涓婅繕姣旀渶浼樺煎皬錛屽壀鏋?br />聽聽聽聽if(cur+song_num-depth<=res)
聽聽聽聽聽聽聽return;聽
聽聽聽聽for(int聽i=last;i<disk_num;++i){
聽聽聽聽聽聽聽聽 //濡傛灉褰撳墠姝屾洸闇瑕佸埢褰曪紝閭e彧闇鍒誨湪絎竴寮犺兘瑁呭緱涓嬬殑鍏夌洏涓娿?br />聽聽聽聽聽聽聽聽if(聽capacity[i]>=songs[depth]){
聽聽聽聽聽聽聽聽聽聽聽聽cur++;
聽聽聽聽聽聽聽聽聽聽聽聽capacity[i]-=songs[depth];
聽聽聽聽聽聽聽聽聽聽聽聽backtracing(depth+1,i);
聽聽聽聽聽聽聽聽聽聽聽聽capacity[i]+=songs[depth];
聽聽聽聽聽聽聽聽聽聽聽聽cur--;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽 // 涓嶅埢褰撳墠姝屾洸
聽聽聽聽backtracing(depth+1,last);
}
void聽solve()
{
聽聽聽聽int聽c;
聽聽聽聽in>>song_num>>c>>disk_num;
聽聽聽聽for(int聽i=0;i<song_num;++i)
聽聽聽聽聽聽聽聽in>>songs[i];
聽聽聽聽for(int聽i=0;i<disk_num;++i)
聽聽聽聽聽聽聽聽capacity[i]聽=聽c;
聽聽聽聽backtracing(0,0);
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
#include聽<cmath>
using聽namespace聽std;
ifstream聽fin("fence9.in");
ofstream聽fout("fence9.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
void聽solve()
{
聽聽聽聽int聽n,m,p;
聽聽聽聽in>>n>>m>>p;
聽聽聽聽int聽res聽=聽0;
聽聽聽聽int聽s,e;
聽聽聽聽for(int聽y=1;y<m;++y){
聽聽聽聽聽聽聽聽s聽=聽n*y/m+1;
聽聽聽聽聽聽聽聽e聽=聽(聽y*(n-p)%m==0聽)聽?聽(y*(n-p)/m-1+p)聽:聽floor(((double)y*(n-p)/m)+p);
聽聽聽聽聽聽//聽聽out<<y<<"聽"<<s<<"聽"<<e<<endl;
聽聽聽聽聽聽聽聽res聽+=聽max(0,(e-s+1));
聽聽聽聽}
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
]]>
銆傛墍浠ユ垜浠塪p[1][start+1][end]鍜宒p[1][start][end-1]涓皬鐨勯偅涓涓?br />濡傛灉player==1錛岄偅鍙兘琚姩鐨勭瓑0鍏堥変簡銆?鍦ㄥ墿涓嬪尯孌典腑錛屽張浣滀負鍏堥夌殑瑙掕壊錛屽嵆player0銆?br />褰撳彧鏈変竴涓暟瀛楃殑鏃跺欙紝player0灝卞彧鏈夐夎繖涓紝player1灝辨病寰楅夛紝榪斿洖0.
浠g爜濡備笅錛?br />
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("game1.in");
ofstream聽fout("game1.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽dp[2][100][100];
int聽sequence[100];
int聽score(int聽player,int聽start,int聽end)
{
聽聽聽聽if(dp[player][start][end]!=-1)
聽聽聽聽聽聽聽聽return聽dp[player][start][end];
聽聽聽聽if(start==end){
聽聽聽聽聽聽聽聽if(player==0)
聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽sequence[start];
聽聽聽聽聽聽聽聽else聽
聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽0;
聽聽聽聽}else{
聽聽聽聽聽聽聽聽int聽t1聽=聽score(0,start+1,end);
聽聽聽聽聽聽聽聽int聽t2聽=聽score(0,start,end-1);
聽聽聽聽聽聽聽聽if(player==0){
聽聽聽聽聽聽聽聽聽聽聽聽if(t1>t2){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽sequence[end]+score(1,start,end-1);
聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽sequence[start]+score(1,start+1,end);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽if(t1>t2){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽score(0,start,end-1);
聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[player][start][end]聽=聽score(0,start+1,end);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽return聽dp[player][start][end];
}
void聽solve()
{
聽聽聽聽memset(dp,-1,sizeof(dp));
聽聽聽聽int聽size;
聽聽聽聽in>>size;
聽聽聽聽for(int聽i=0;i<size;++i)
聽聽聽聽聽聽聽聽in>>sequence[i];
聽聽聽聽out<<score(0,0,size-1)<<"聽"<<score(1,0,size-1)<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("range.in");
ofstream聽fout("range.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
bool聽dp[250][250];
int聽side_len;
void聽input()
{
聽聽聽聽in>>side_len;
聽聽聽聽char聽t;
聽聽聽聽for(int聽i=0;i<side_len;++i){
聽聽聽聽聽聽聽聽for(int聽j=0;j<side_len;++j){
聽聽聽聽聽聽聽聽聽聽聽聽while(聽in.get(t)&&isspace(t)聽);
聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j]聽=聽t-'0';
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽input();
聽聽聽聽for(int聽w聽=聽2;w<=side_len;++w){
聽聽聽聽聽聽聽聽int聽cnt聽=聽0;
聽聽聽聽聽聽聽聽for(int聽i=0;i<side_len;++i){
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽j=0;j<side_len;++j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i+w<=side_len&&j+w<=side_len){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽dp[i][j]聽=聽dp[i][j]&&dp[i+1][j]&&dp[i][j+1]&&dp[i+1][j+1];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(dp[i][j])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽cnt++;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(cnt!=0){
聽聽聽聽聽聽聽聽聽聽聽聽out<<w<<"聽"<<cnt<<endl;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
]]>
]]>
#include聽<fstream>
#include聽<set>
#include聽<queue>
using聽namespace聽std;
ifstream聽fin("msquare.in");
ofstream聽fout("msquare.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽final[8];
set<int>visited;
char聽result[8*7*6*5*4*3*2*1+1];
struct聽queue_node{
聽聽聽聽int聽current[8];
聽聽聽聽queue_node聽*parent;
聽聽聽聽char聽op;
};
void聽op(int聽*current,char聽c)
{
聽聽聽聽int聽tmp;
聽聽聽聽switch(c){
聽聽聽聽聽聽聽聽case聽'A':
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=0;i<4;++i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽swap(current[i],current[7-i]);
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽'B':
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[3];
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=3;i>=1;--i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽current[i]聽=聽current[i-1];
聽聽聽聽聽聽聽聽聽聽聽聽current[0]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[4];
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=4;i<=6;++i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽current[i]聽=聽current[i+1];
聽聽聽聽聽聽聽聽聽聽聽聽current[7]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽'C':
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[6];
聽聽聽聽聽聽聽聽聽聽聽聽current[6]聽=聽current[5];
聽聽聽聽聽聽聽聽聽聽聽聽current[5]聽=聽current[2];
聽聽聽聽聽聽聽聽聽聽聽聽current[2]聽=聽current[1];
聽聽聽聽聽聽聽聽聽聽聽聽current[1]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽}
}
int聽cur_value(int聽*cur)
{
聽聽聽聽int聽res聽=聽0;
聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽res*=10;
聽聽聽聽聽聽聽聽res+=cur[i];
聽聽聽聽}
聽聽聽聽return聽res;
}
void聽solve()
{
聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽in>>final[i];
聽聽聽聽}
聽聽聽聽queue<queue_node*>聽q;
聽聽聽聽queue_node聽*node聽=聽new聽queue_node;
聽聽聽聽for(int聽i=0;i<8;++i)
聽聽聽聽聽聽聽聽node->current[i]聽=聽i+1;
聽聽聽聽node->parent聽=聽NULL;
聽聽聽聽q.push(node);
聽聽聽聽while(聽!q.empty()聽){
聽聽聽聽聽聽聽聽queue_node聽*node聽=聽q.front();
聽聽聽聽聽聽聽聽q.pop();
聽聽聽聽聽聽聽聽int聽cur聽=聽cur_value(node->current);
聽聽聽聽聽聽聽聽if(聽visited.find(聽cur)聽!=聽visited.end())
聽聽聽聽聽聽聽聽聽聽聽聽continue;
聽聽聽聽聽聽聽聽visited.insert(cur);
聽聽聽聽聽聽聽聽bool聽ok聽=聽true;
聽聽聽聽聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽聽聽聽聽if(node->current[i]!=final[i]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ok聽=聽false;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(ok){
聽聽聽聽聽聽聽聽聽聽聽聽int聽i聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽while(node->parent!=NULL){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽result[i++]聽=聽node->op;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node=node->parent;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽if(i==0){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<0<<endl<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽out<<i<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽int聽j;
聽聽聽聽聽聽聽聽聽聽聽聽i--;
聽聽聽聽聽聽聽聽聽聽聽聽for(j=0;i>=0;i--,j++){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<result[i];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j%60==59)聽out<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽if(j%60!=0)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽for(char聽c='A';c<='C';++c){
聽聽聽聽聽聽聽聽聽聽聽聽queue_node聽*聽n聽=聽new聽queue_node;
聽聽聽聽聽聽聽聽聽聽聽聽memcpy(n->current,node->current,sizeof(node->current));
聽聽聽聽聽聽聽聽聽聽聽聽op(n->current,c);
聽聽聽聽聽聽聽聽聽聽聽聽n->op聽=聽c;
聽聽聽聽聽聽聽聽聽聽聽聽n->parent聽=聽node;
聽聽聽聽聽聽聽聽聽聽聽聽q.push(n);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream in("spin.in");
ofstream out("spin.out");
struct聽wedge{
聽聽聽聽int聽start;
聽聽聽聽int聽extent;
};
int聽speed[5];
wedge聽wedges[5][5];
int聽wedge_num[5];
void聽onesecond()
{
聽聽聽for(int聽i=0;i<5;++i){
聽聽聽聽聽聽聽for(int聽j=0;j<wedge_num[i];++j){
聽聽聽聽聽聽聽聽聽聽聽wedges[i][j].start+=speed[i];
聽聽聽聽聽聽聽聽聽聽聽wedges[i][j].start%=360;
聽聽聽聽聽聽聽}
聽聽聽}聽
}
bool聽isok()
{
聽聽聽聽int聽tmp[360];
聽聽聽聽memset(tmp,0,sizeof(tmp));
聽聽聽聽for(int聽i=0;i<5;++i){
聽聽聽聽聽聽聽聽for(int聽j=0;j<wedge_num[i];++j){
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽k=0;k<=wedges[i][j].extent;++k)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽tmp[(wedges[i][j].start+k)%360]++;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<360;++i)
聽聽聽聽聽聽聽聽if(tmp[i]==5)
聽聽聽聽聽聽聽聽聽聽聽聽return聽true;
聽聽聽聽return聽false;
}
void聽solve()
{
聽聽聽聽for(int聽i=0;i<5;++i){
聽聽聽聽聽聽聽聽in>>speed[i];
聽聽聽聽聽聽聽聽in>>wedge_num[i];
聽聽聽聽聽聽聽聽for(int聽j=0;j<wedge_num[i];++j){
聽聽聽聽聽聽聽聽聽聽聽聽in>>wedges[i][j].start>>wedges[i][j].extent;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽if(isok()){
聽聽聽聽聽聽聽聽out<<0<<endl;
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽聽for(int聽i=1;i<=360;++i){
聽聽聽聽聽聽聽聽onesecond();
聽聽聽聽聽聽聽聽if(isok()){
聽聽聽聽聽聽聽聽聽聽聽聽out<<i<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽return;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽out<<"none"<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("kimbits.in");
ofstream聽fout("kimbits.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
unsigned聽int聽cmb_num[32][32];
void聽build_cmb_num()
{
聽聽聽聽for(int聽i=0;i<32;++i)
聽聽聽聽聽聽聽聽cmb_num[i][0]聽=聽1;
聽聽聽聽for(int聽i=1;i<32;++i)
聽聽聽聽聽聽聽聽for(int聽j=1;j<=i;++j)
聽聽聽聽聽聽聽聽聽聽聽聽cmb_num[i][j]聽=聽cmb_num[i-1][j-1]+cmb_num[i-1][j];
聽聽聽聽for(int聽i=0;i<32;++i)
聽聽聽聽聽聽聽聽for(int聽j=1;j<32;++j){
聽聽聽聽聽聽聽聽聽聽聽聽cmb_num[i][j]+=cmb_num[i][j-1];
聽聽聽聽聽聽聽聽}
}
void聽solve()
{
聽聽聽聽build_cmb_num();
聽聽聽聽unsigned聽聽n,l,i;
聽聽聽聽in>>n>>l>>i;
聽聽聽聽for(unsigned聽idx=n;idx>0;--idx){
聽聽聽聽聽聽聽聽if(聽i>聽cmb_num[idx-1][l]聽){
聽聽聽聽聽聽聽聽聽聽聽聽out<<1;
聽聽聽聽聽聽聽聽聽聽聽聽i-=cmb_num[idx-1][l];
聽聽聽聽聽聽聽聽聽聽聽聽l--;
聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽out<<0;
聽聽聽聽聽聽聽聽}聽聽聽
聽聽聽聽}
聽聽聽聽out<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
Kim SchrijversPROGRAM NAME: kimbits
INPUT FORMAT
A single line with three space separated integers: N, L, and I.
SAMPLE INPUT (file kimbits.in)
5 3 19
OUTPUT FORMAT
A single line containing the integer that represents the Ith element
from the order set, as described.
SAMPLE OUTPUT (file kimbits.out)
10011
]]>
n/5+n/5/5+n/5/5/5+n/5/5/5/5+n/5/5/5/5/5+n/5/5/5/5/5/5;
鐒跺悗鍐嶅幓闄ょ浉搴旀暟鐩殑2銆傝繖鏍峰墿涓嬬殑鏁板彧闇涓や袱鐩鎬箻鍚庡彇鏈鍚庝竴浣嶅嵆鍙?br />
#include聽<fstream>
using聽namespace聽std;
ifstream in("fact4.in");
ofstream out("fact4.out");
void聽solve()
{
聽聽聽聽int聽n;
聽聽聽聽in>>n;
聽聽聽聽int聽numof5聽=聽n/5+n/5/5+n/5/5/5+n/5/5/5/5+n/5/5/5/5/5+n/5/5/5/5/5/5;
聽聽聽聽int聽res聽=聽1;
聽聽聽聽int聽tmp;
聽聽聽聽for(int聽i=1;i<=n;++i){
聽聽聽聽聽聽聽聽tmp聽=聽i;
聽聽聽聽聽聽聽聽while(tmp%5==0)聽tmp/=5;
聽聽聽聽聽聽聽聽while(tmp%2==0&&numof5!=0){
聽聽聽聽聽聽聽聽聽聽聽聽tmp/=2;
聽聽聽聽聽聽聽聽聽聽聽聽numof5--;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽res*=tmp;
聽聽聽聽聽聽聽聽res%=10;
聽聽聽聽}
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
鍘熼錛?br />PROGRAM NAME: fact4
INPUT FORMAT
A single positive integer N no larger than 4,220.
SAMPLE INPUT (file fact4.in)
7
OUTPUT FORMAT
A single line containing but a single digit: the right most non-zero
digit of N! .
SAMPLE OUTPUT (file fact4.out)
4
]]>
#include聽<fstream>
#include聽<vector>
#include聽<string>
using聽namespace聽std;
ifstream聽fin("contact.in");
ofstream聽fout("contact.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
struct聽trie_node{
聽聽聽聽int聽cnt;
聽聽聽聽trie_node*聽sons[2];
聽聽聽聽trie_node(){
聽聽聽聽聽聽聽聽sons[0]聽=聽sons[1]聽=聽0;
聽聽聽聽聽聽聽聽cnt聽=聽0;
聽聽聽聽}
};
struct聽sort_node{
聽聽聽聽string聽str;
聽聽聽聽int聽cnt;
聽聽聽聽bool聽operator<(const聽sort_node&n2)聽const{
聽聽聽聽聽聽聽聽if(cnt!=n2.cnt)聽return聽cnt>n2.cnt;
聽聽聽聽聽聽聽聽if(str.size()!=n2.str.size())聽return聽str.size()<n2.str.size();
聽聽聽聽聽聽聽聽for(int聽i=0;i<str.size();++i){
聽聽聽聽聽聽聽聽聽聽聽聽if(str[i]!=n2.str[i])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽str[i]<n2.str[i];
聽聽聽聽聽聽聽聽}
聽聽聽聽}
};
char聽buf[200000];
int聽buf_len;
int聽a,b,n;
vector<sort_node>res;
void聽insert_trie(trie_node*root,const聽char聽*start,int聽len)
{
聽聽聽聽trie_node聽*聽next聽=聽root;
聽聽聽聽for(int聽i=0;i<len;++i){
聽聽聽聽聽聽聽聽if(next->sons[start[i]-'0']==NULL)
聽聽聽聽聽聽聽聽聽聽聽聽next->sons[start[i]-'0']聽=聽new聽trie_node;
聽聽聽聽聽聽聽聽next聽=聽next->sons[start[i]-'0'];
聽聽聽聽聽聽聽聽if(i+1>=a&&i+1<=b)
聽聽聽聽聽聽聽聽聽聽聽聽next->cnt++;
聽聽聽聽}
}
void聽_traverse_trie(trie_node聽*root,char聽ch,int聽depth)
{
聽聽聽聽if(root==NULL)聽return;
聽聽聽聽buf[depth]=ch;
聽聽聽聽if(root->cnt!=0){
聽聽聽聽聽聽聽聽sort_node聽n;
聽聽聽聽聽聽聽聽n.str聽=聽string(&buf[0],&buf[depth+1]);
聽聽聽聽聽聽聽聽n.cnt聽=聽root->cnt;
聽聽聽聽聽聽聽聽res.push_back(n);
聽聽聽聽}
聽聽聽聽_traverse_trie(root->sons[0],'0',depth+1);
聽聽聽聽_traverse_trie(root->sons[1],'1',depth+1);
}
void聽traverse_trie(trie_node聽*root)
{
聽聽聽聽_traverse_trie(root->sons[0],'0',0);
聽聽聽聽_traverse_trie(root->sons[1],'1',0);
}
void聽solve()
{
聽聽聽聽in>>a>>b>>n;
聽聽聽聽char聽ch;
聽聽聽聽while(in.get(ch)){
聽聽聽聽聽聽聽聽if(ch=='0'||ch=='1')
聽聽聽聽聽聽聽聽聽聽聽聽buf[buf_len++]聽=聽ch;
聽聽聽聽}
聽聽聽聽trie_node聽root;
聽聽聽聽for(int聽i=0;i+b<=buf_len;++i){
聽聽聽聽聽聽聽聽insert_trie(&root,&buf[i],b);
聽聽聽聽}
聽聽聽聽for(int聽i=min(b-1,buf_len);i>=a;--i){
聽聽聽聽聽聽聽聽insert_trie(&root,&buf[buf_len-i],i);
聽聽聽聽}
聽聽聽聽traverse_trie(&root);
聽聽聽聽sort(res.begin(),res.end());
聽聽聽聽int聽freq_cnt聽=聽0;
聽聽聽聽int聽last_cnt聽=聽-1;
聽聽聽聽int聽out_cnt聽=聽0;
聽聽聽聽for(int聽i=0;i<res.size();++i){
聽聽聽聽聽聽聽聽if(res[i].cnt==last_cnt){
聽聽聽聽聽聽聽聽聽聽聽聽if(out_cnt%6!=0)
聽聽聽聽聽聽聽聽聽聽聽聽out<<"聽";
聽聽聽聽聽聽聽聽聽聽聽聽out<<res[i].str;
聽聽聽聽聽聽聽聽聽聽聽聽out_cnt++;
聽聽聽聽聽聽聽聽聽聽聽聽if(out_cnt%6==0||i==(res.size()-1)||res[i+1].cnt!=res[i].cnt)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<endl;
聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽last_cnt聽=聽res[i].cnt;
聽聽聽聽聽聽聽聽聽聽聽聽freq_cnt++;
聽聽聽聽聽聽聽聽聽聽聽聽if(freq_cnt>n)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽break;聽
聽聽聽聽聽聽聽聽聽聽聽聽out<<res[i].cnt<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽out<<res[i].str;
聽聽聽聽聽聽聽聽聽聽聽聽out_cnt聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽out_cnt++;
聽聽聽聽聽聽聽聽聽聽聽聽if(聽(i==res.size()-1)||res[i+1].cnt!=res[i].cnt)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<endl;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
闄勯錛?br />
IOI'98PROGRAM NAME: contact
INPUT FORMAT
Line 1: Three space-separated integers: A, B, N; (1
<= N < 50) Lines 2 and beyond: A sequence of as many as 200,000
characters, all 0 or 1; the characters are presented 80 per line, except
potentially the last line. SAMPLE INPUT (file contact.in)
2 4 10
01010010010001000111101100001010011001111000010010011110010000000OUTPUT FORMAT
SAMPLE OUTPUT (file contact.out)
23
00
15
01 10
12
100
11
11 000 001
10
010
8
0100
7
0010 1001
6
111 0000
5
011 110 1000
4
0001 0011 1100
]]>
]]>
]]>
]]>
]]>
]]>
]]>
棣栧厛鐢?floyd璁$畻鍑轟袱涓や箣闂寸殑鏈鐭礬寰勩傜劧鍚庣敤dfs灝嗗浘鐫鑹層傚姣忎袱涓や笉鍚岄鑹茬殑緇撶偣錛屾垜浠妸瀹冧滑鐩歌繛錛岀劧鍚庣湅浜х敓鐨勫浘鐨勭洿寰勭殑澶у皬銆?br />鐩村緞鐨勫ぇ灝忓彧鍙兘浠嶄負鍘熶袱榪為氬浘鐩村緞涔嬩竴錛屾垨鑰呮槸鍖呮嫭鏂版坊鍔犵殑璺緞鎵浜х敓鐨勬渶闀胯礬寰勶紝鍙栬繖涓夎呬腑鐨勬渶澶у箋傛柊璺緞浜х敓鐨勬渶闀胯礬寰勫彧鍙兘鏄袱鐐圭殑璺濈鍔犱笂涓ょ偣鍒板叾浠栫偣鐨勬渶闀胯窛紱匯傛渶寮濮嬬殑鏃跺欏彧鑰冭檻浜嗘柊娣誨姞鐨勮礬寰勶紝娌¤冭檻鍘熺洿寰勪細姣旀柊璺緞澶х殑鎯呭喌錛寃a浜唍嬈°傘?br />
#include聽<fstream>
#include聽<cfloat>
#include聽<cmath>
using聽namespace聽std;
ifstream聽fin("cowtour.in");
ofstream聽fout("cowtour.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
double聽path[150][150];
char聽graph[150][150];
int聽x[150];
int聽y[150];
int聽n;
int聽color[150];
double聽diameter[150];
double聽maxPath[150];
void聽floyd()
{
聽聽聽聽for(int聽k=0;k<n;++k)
聽聽聽聽聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
}
void聽make_color(int聽i,int聽c)
{
聽聽聽聽if(聽color[i]!=0聽)
聽聽聽聽聽聽聽聽return;
聽聽聽聽color[i]聽=聽c;
聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽if(color[j]==0&&graph[i][j])
聽聽聽聽聽聽聽聽聽聽聽聽make_color(j,c);
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>n;
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽in>>x[i]>>y[i];
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽string聽s;
聽聽聽聽聽聽聽聽in>>s;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽graph[i][j]=s[j]-'0';
聽聽聽聽聽聽聽聽聽聽聽聽if(graph[i][j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽+(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽DBL_MAX/4;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽floyd();
聽聽聽聽int聽c聽=聽0;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽if(color[i]==0)
聽聽聽聽聽聽聽聽聽聽聽聽make_color(i,++c);
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽maxPath[i]聽=聽0;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j&&color[i]==color[j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽maxPath[i]聽=聽max(maxPath[i],path[i][j]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽diameter[color[i]]聽=聽max(diameter[color[i]],maxPath[i]);
聽聽聽聽}
聽聽聽聽double聽dia聽=聽DBL_MAX;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽for(int聽j=i+1;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(color[i]==color[j])聽continue;
聽聽聽聽聽聽聽聽聽聽聽聽double聽d1聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=p&&color[i]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d1聽=聽max(d1,path[i][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽d2聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j!=p&&color[j]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d2聽=聽max(d2,path[j][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽dist聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽dia聽=聽min(dia,max(d1+d2+dist,max(diameter[color[i]],diameter[color[j]]))聽);
聽聽聽聽聽聽聽聽}
聽聽聽聽out.setf(ios::fixed,ios::floatfield);
聽聽聽聽out.precision(6);
聽聽聽聽out<<dia<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
#include聽<queue>
using聽namespace聽std;
ifstream聽fin("maze1.in");
ofstream聽fout("maze1.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
char聽maze[2*100+1][2*38+1];
bool聽visited[100][38];
int聽shortest1[100][38];
int聽shortest2[100][38];
bool聽get_first;
int聽exit1r,exit1c;
int聽exit2r,exit2c;
int聽w,h;
struct聽queue_node{
聽聽聽聽int聽i,j,depth;
聽聽聽聽queue_node(int聽i,int聽j,int聽depth){
聽聽聽聽聽聽聽聽this->i聽=聽i;
聽聽聽聽聽聽聽聽this->j聽=聽j;
聽聽聽聽聽聽聽聽this->depth聽=聽depth;
聽聽聽聽}
};
void聽bfs(int聽i,int聽j,int聽shortest[100][38])
{
聽聽聽聽queue<queue_node>q;
聽聽聽聽q.push(queue_node(i,j,1));
聽聽聽聽while(!q.empty()){
聽聽聽聽聽聽聽聽queue_node聽node聽=聽q.front();
聽聽聽聽聽聽聽聽q.pop();
聽聽聽聽聽聽聽聽if(visited[node.i][node.j])
聽聽聽聽聽聽聽聽聽聽聽聽continue;
聽聽聽聽聽聽聽聽visited[node.i][node.j]聽=聽true;
聽聽聽聽聽聽聽聽shortest[node.i][node.j]聽=聽node.depth;
聽聽聽聽聽聽聽聽if(node.i!=0&&maze[2*node.i][2*node.j+1]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i-1,node.j,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.i!=h-1&&maze[2*node.i+2][2*node.j+1]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i+1,node.j,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.j!=0&&maze[2*node.i+1][2*node.j]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i,node.j-1,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.j!=w-1&&maze[2*node.i+1][2*node.j+2]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i,node.j+1,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>w>>h;
聽聽聽聽for(int聽i=0;i<2*h+1;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<2*w+1;++j){
聽聽聽聽聽聽聽聽聽聽聽聽do{
聽聽聽聽聽聽聽聽聽聽聽聽in.get(maze[i][j]);
聽聽聽聽聽聽聽聽聽聽聽聽}while(maze[i][j]=='\n');
聽聽聽聽聽聽聽聽聽聽聽聽if((i==0||i==2*h||j==0||j==2*w)&&maze[i][j]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(!get_first){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i==2*h)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1r聽=聽h-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1r聽=聽i/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j==2*w)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1c聽=聽w-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1c聽=聽j/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽get_first聽=聽true;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i==2*h)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2r聽=聽h-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2r聽=聽i/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j==2*w)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2c聽=聽w-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2c聽=聽j/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽memset(visited,0,sizeof(visited));
聽聽聽聽bfs(exit1r,exit1c,shortest1);
聽聽聽聽memset(visited,0,sizeof(visited));
聽聽聽聽bfs(exit2r,exit2c,shortest2);
聽聽聽聽int聽res聽=聽INT_MIN;
聽聽聽聽for(int聽i=0;i<h;++i)
聽聽聽聽聽for(int聽j=0;j<w;++j){
聽聽聽聽聽聽聽聽聽res聽=聽max(res,聽min(shortest1[i][j],shortest2[i][j])聽);
聽聽聽聽聽}
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("ttwo.in");
ofstream聽fout("ttwo.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
char聽grid[10][10];
bool聽visited[10][10][4][10][10][4];
int聽north聽=聽0;
int聽east聽=聽1;
int聽south聽=聽2;
int聽west聽=聽3;
//鏂瑰悜涓?,1,2,3鏃跺悜鍓嶈蛋涓姝ow鍜宑olumn鐨勫鍔犲?/span>
int聽delr[4]聽=聽{
聽聽聽聽-1,0,1,0
};
int聽delc[4]聽=聽{
聽聽聽聽0,1,0,-1
};
//聽farmer鐨勫綋鍓峳ow,column,direction.
int聽fc,fr,fd;
int聽cc,cr,cd;
bool聽available(int聽i,int聽j)
{
聽聽聽聽if(i>=0&&i<=9&&j>=0&&j<=9&&grid[i][j]!='*')
聽聽聽聽聽聽聽聽return聽true;
聽聽聽聽else
聽聽聽聽聽聽聽聽return聽false;
}
void聽one_step()
{
聽聽聽聽if(聽available(聽fr+delr[fd],fc+delc[fd]聽)聽){
聽聽聽聽聽聽聽聽fr聽+=聽delr[fd];
聽聽聽聽聽聽聽聽fc聽+=聽delc[fd];
聽聽聽聽}else{
聽聽聽聽聽聽聽聽fd+=1;
聽聽聽聽聽聽聽聽fd%=4;
聽聽聽聽}
聽聽聽聽if(聽available(聽cr+delr[cd],cc+delc[cd]聽)聽){
聽聽聽聽聽聽聽聽cr聽+=聽delr[cd];
聽聽聽聽聽聽聽聽cc聽+=聽delc[cd];
聽聽聽聽}else{
聽聽聽聽聽聽聽聽cd+=1;
聽聽聽聽聽聽聽聽cd%=4;
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽for(int聽i=0;i<10;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<10;++j){
聽聽聽聽聽聽聽聽聽聽聽聽in>>grid[i][j];
聽聽聽聽聽聽聽聽聽聽聽聽if(grid[i][j]=='F')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽fr=i,fc=j,fd=0;
聽聽聽聽聽聽聽聽聽聽聽聽if(grid[i][j]=='C')
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽cr=i,cc=j,cd=0;
聽聽聽聽聽聽聽聽}
聽聽聽聽memset(visited,0,sizeof(visited));
聽聽聽聽visited[fc][fr][fd][cc][cr][cd]聽=聽true;
聽聽聽聽int聽res聽=聽0;
聽聽聽聽while(true){
聽聽聽聽聽聽聽聽one_step();
聽聽聽聽聽聽聽聽res++;
聽聽聽聽聽聽聽聽if(聽fc==cc&&fr==cr聽){
聽聽聽聽聽聽聽聽聽聽聽聽out<<res<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(visited[fc][fr][fd][cc][cr][cd]){
聽聽聽聽聽聽聽聽聽聽聽聽out<<0<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽visited[fc][fr][fd][cc][cr][cd]=true;
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("concom.in");
ofstream聽fout("concom.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽stock[101][101];
int聽n;
bool聽control[101];
void聽add_control(int聽cr,int聽ce)
{
聽聽聽聽if(control[ce])聽return;
聽聽聽聽control[ce]聽=聽true;
聽聽聽聽for(int聽i聽=聽1;聽i<=100;聽++i){
聽聽聽聽聽聽聽聽if(i!=cr&&!control[i]){
聽聽聽聽聽聽聽聽聽聽聽聽stock[cr][i]+=stock[ce][i];
聽聽聽聽聽聽聽聽聽聽聽聽if(stock[cr][i]>50)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽add_control(cr,i);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽memset(stock,0,sizeof(stock));
聽聽聽聽
聽聽聽聽in>>n;
聽聽聽聽int聽i,j,p;
聽聽聽聽while(n--){
聽聽聽聽聽聽聽聽in>>i>>j>>p;
聽聽聽聽聽聽聽聽stock[i][j]聽=聽p;
聽聽聽聽}
聽聽聽聽
聽聽聽for(int聽i=1;i<=100;++i){
聽聽聽聽聽聽聽memset(control,0,sizeof(control));
聽聽聽聽聽聽聽for(int聽j=1;j<=100;++j){
聽聽聽聽聽聽聽聽聽聽聽if(i==j)聽continue;
聽聽聽聽聽聽聽聽聽聽聽if(聽stock[i][j]>50){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽add_control(i,j);
聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽for(int聽j=1;j<=100;++j){
聽聽聽聽聽聽聽聽聽聽聽if(control[j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<i<<'聽'<<j<<endl;
聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽}
聽聽聽}聽
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
]]>
]]>
]]>
]]>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("runround.in");
ofstream聽fout("runround.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽m;
bool聽mark[10];
int聽figures[10];
void聽solve();
void聽permutation(int聽max_dep);
unsigned聽long聽get_value(int聽len);
bool聽isok(int聽len);
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
void聽solve()
{
聽聽聽聽in>>m;
聽聽聽聽int聽start聽=聽0;
聽聽聽聽int聽tmp聽=聽m;
聽聽聽聽while(tmp){
聽聽聽聽聽聽聽聽tmp/=10;
聽聽聽聽聽聽聽聽start++;
聽聽聽聽}
聽聽聽聽for(int聽i=start;i<=9;++i){
聽聽聽聽聽聽聽聽permutation(i);
聽聽聽聽}
}
void聽_permutation(int聽depth,int聽max_dep)
{
聽聽聽聽if(depth==max_dep){
聽聽聽聽聽聽if(isok(max_dep)){
聽/*聽聽聽聽聽聽聽聽for(int聽i=0;i<max_dep;++i)
聽聽聽聽聽聽聽聽聽聽聽聽cout<<figures[i]<<'聽';
聽聽聽聽聽聽聽聽cout<<endl;
聽聽*/聽聽聽聽聽聽聽unsigned聽long聽t聽=聽get_value(max_dep);
聽聽聽聽聽聽聽聽聽聽聽聽if(t>m){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<t<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽聽for(int聽i=1;i<=9;++i){
聽聽聽聽聽聽聽聽if(!mark[i]){
聽聽聽聽聽聽聽聽聽聽聽聽mark[i]聽=聽true;
聽聽聽聽聽聽聽聽聽聽聽聽figures[depth]聽=聽i;
聽聽聽聽聽聽聽聽聽聽聽聽_permutation(depth+1,max_dep);
聽聽聽聽聽聽聽聽聽聽聽聽mark[i]聽=聽false;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
//鐢熸垚闀垮害涓簂en鐨勫叏鎺掑垪
void聽permutation(int聽len)
{
聽聽聽聽memset(mark,0,sizeof(mark));
聽聽聽聽_permutation(0,len);
}
//鏄痳unaround鏁?/span>
bool聽isok(int聽len)
{
聽聽聽聽int聽unvisited聽=聽len;
聽聽聽聽bool聽mark[10];
聽聽聽聽memset(mark,0,sizeof(mark));
聽聽聽聽int聽i聽=聽0;
聽聽聽聽while(unvisited--){
聽聽聽聽聽聽聽i+=figures[i];聽i%=(len);
聽聽聽聽聽聽聽if(mark[i])聽return聽false;
聽聽聽聽聽聽聽mark[i]聽=聽true;
聽聽聽聽}
聽聽聽聽return聽true;
}
//灝嗘暟緇勮漿鍖栨垚unsigned聽long
unsigned聽long聽get_value(int聽len)
{
聽聽聽聽unsigned聽long聽res聽=聽0;
聽聽聽聽for(int聽i=0;i<len;++i){
聽聽聽聽聽聽聽聽res*=10;
聽聽聽聽聽聽聽聽res+=figures[i];
聽聽聽聽}
聽聽聽聽return聽res;
}
]]>
鍓╀笅灝辨槸鍑犱釜鎿嶄綔鐨勬帓鍒楃粍鍚堜簡銆備唬鐮佸啓寰楀緢綣?..
#include聽<fstream>
#include聽<vector>
#include聽<algorithm>
using聽namespace聽std;
ifstream聽fin("lamps.in");
ofstream聽fout("lamps.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
struct聽state_node{
聽聽聽聽bool聽states[101];
聽聽聽聽int聽len;
聽聽聽聽bool聽operator<(const聽state_node聽&聽n1)聽const{
聽聽聽聽聽聽聽聽for(int聽i=1;i<=len;++i){
聽聽聽聽聽聽聽聽聽聽聽聽if(states[i]!=n1.states[i])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽states[i]<n1.states[i];
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return聽false;
聽聽聽聽}
聽聽聽聽bool聽operator==(const聽state_node聽&聽n1)聽const{
聽聽聽聽聽聽聽聽for(int聽i=1;i<=len;++i){
聽聽聽聽聽聽聽聽聽聽聽聽if(states[i]!=n1.states[i])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return聽false;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return聽true;
聽聽聽聽}
};
state_node聽node;
int聽n,c;
vector<int>finalon,finaloff;
vector<state_node>聽result;
void聽op(int聽kind)
{
聽聽聽聽switch(kind){
聽聽聽聽聽聽聽聽case聽1:
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=1;i<=n;++i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node.states[i]=!node.states[i];
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽2:
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=1;i<=n;++i){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i&1)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node.states[i]=!node.states[i];
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽3:
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=1;i<=n;++i){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(!(i&1))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node.states[i]=!node.states[i];
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽4:
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=1;i<=n;++i){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i%3==1){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node.states[i]=!node.states[i];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽}
}
bool聽isok()
{
聽聽聽聽for(int聽i=0;i<finalon.size();++i){
聽聽聽聽聽聽聽聽if(!node.states[finalon[i]])
聽聽聽聽聽聽聽聽聽聽聽聽return聽false;
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<finaloff.size();++i){
聽聽聽聽聽聽聽聽if(node.states[finaloff[i]])
聽聽聽聽聽聽聽聽聽聽聽聽return聽false;
聽聽聽聽}
聽聽聽聽return聽true;
}
void聽do0()
{
聽聽聽聽if(isok())
聽聽聽聽聽聽聽聽result.push_back(node);
}
void聽do1()
{
聽聽聽聽for(int聽i=1;i<=4;++i){
聽聽聽聽聽聽聽聽op(i);
聽聽聽聽聽聽聽聽if(isok()){
聽聽聽聽聽聽聽聽聽聽聽聽result.push_back(node);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽op(i);
聽聽聽聽}
}
void聽do2()
{
聽聽聽聽for(int聽i=1;i<=3;++i){
聽聽聽聽聽聽聽聽for(int聽j=i+1;j<=4;++j){
聽聽聽聽聽聽聽聽聽聽聽聽op(i);
聽聽聽聽聽聽聽聽聽聽聽聽op(j);
聽聽聽聽聽聽聽聽聽聽聽聽if(isok()){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽result.push_back(node);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽op(i);
聽聽聽聽聽聽聽聽聽聽聽聽op(j);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
void聽do3()
{
聽聽聽聽//鎿嶄綔1,2,3,4鍚勬墽琛屼竴嬈★紝鍓嶄笁涓搷浣滄姷娑?/span>
聽聽聽聽op(4);
聽聽聽聽do1();
}
void聽do4()
{
聽聽聽聽op(4);
聽聽聽聽if(isok()){
聽聽聽聽聽聽聽聽result.push_back(node);
聽聽聽聽}
聽聽聽聽op(4);
}
void聽action(int聽i)
{
聽聽聽聽switch(i){
聽聽聽聽聽聽聽聽case聽0:聽do0();break;
聽聽聽聽聽聽聽聽case聽1:聽do1();break;
聽聽聽聽聽聽聽聽case聽2:聽do2();break;
聽聽聽聽聽聽聽聽case聽3:聽do3();break;
聽聽聽聽聽聽聽聽case聽4:聽do4();break;
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>n>>c;
聽聽聽聽node.len聽=聽n;
聽聽聽聽for(int聽i=1;i<=n;++i)聽
聽聽聽聽聽聽聽聽node.states[i]聽=聽true;
聽聽聽聽int聽t;
聽聽聽聽do{
聽聽聽聽聽聽聽聽in>>t;
聽聽聽聽聽聽聽聽if(t!=-1)
聽聽聽聽聽聽聽聽聽聽聽聽finalon.push_back(t);
聽聽聽聽}while(t!=-1);
聽聽聽聽聽do{
聽聽聽聽聽聽聽聽in>>t;
聽聽聽聽聽聽聽聽if(t!=-1)
聽聽聽聽聽聽聽聽聽聽聽聽finaloff.push_back(t);
聽聽聽聽}while(t!=-1);
聽聽聽聽bool聽has_result聽=聽false;
聽聽聽聽for(int聽i=0;i<=4;++i){
聽聽聽聽聽聽聽聽if(c>=i&&(c-i)%2==0){
聽聽聽聽聽聽聽聽聽聽聽聽action(i);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽sort(result.begin(),result.end());
聽聽聽聽vector<state_node>::iterator聽end聽=聽
聽聽聽聽聽聽聽聽unique(result.begin(),result.end());
聽聽聽聽for(vector<state_node>::iterator聽i聽=聽result.begin();
聽聽聽聽聽聽聽聽聽聽聽聽i!=end;聽++i){
聽聽聽聽聽聽聽聽has_result聽=聽true;
聽聽聽聽聽聽聽聽for(int聽j=1;j<=n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽out<<i->states[j];
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽out<<endl;
聽聽聽聽}
聽聽聽聽if(!has_result){
聽聽聽聽聽聽聽聽out<<"IMPOSSIBLE"<<endl;
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>