锘??xml version="1.0" encoding="utf-8" standalone="yes"?> baby_step gaint_step 綆楁硶鍩烘湰鎬濇兂: 瀵逛簬涓涓猲涓厓绱犵殑寰幆(n寰堝ぇ寰堝ぇ) 鍏堢畻鍑哄墠闈姝?baby_step) 鐒跺悗浠涓鴻法搴?gaint_step)澶ц煩 閭d箞璺充簡n/m姝ヤ互鍚?涓瀹氳兘璺沖埌鍓嶉潰綆楀嚭鏉ョ殑m姝ラ噷闈?榪欐牱鏃墮棿澶嶆潅搴﹀氨闄嶅埌O(m+n/m) 絀洪棿澶嶆潅搴︿負(fù)O(m) 瀵逛簬璁$畻a^x==b(mod n)涓殑x 鍏堣綆梑,b*a,b*a^2,...b*a^m 鐒跺悗璁$畻1錛宎^m,a^2m,a^3m,... 閭d箞緇忚繃i姝?灝辨槸鍒頒簡a^(i*m)鐨勬椂鍊?鍙戠幇瀹冪瓑浜巄*a^j 閭d箞x=i*m-j 涓鑸琺瀹氫負(fù)sqrt(n)騫寵 鏃剁┖(騫朵笖榪欐牱鏃墮棿澶嶆潅搴︽渶浣庯級(jí) 鏌ユ壘鐢╤ash 浜嬪疄璇佹槑map鏄潪甯告參鐨?/p> //鏇存柊 緇忚繃AekdyCoin鐩栦笘紲炵墰鐨勬楠?鎴戦偅涓兘鍦╬oj涓婅窇鐨勭▼搴忓湪hdu涓婂厛MLE 鐒跺悗TLE 鐒跺悗CE 鐒跺悗RE 鐒跺悗WA 鍗冭緵涓囪嫤 鏈鍚庤煩榪嘝E 鍙樻垚AC浜?/p> 鍘熷洜:鍔ㄦ侀摼琛╤ash璺戝お鎱?浠ュ悗瑕佹敼鎴愬墠鍚戞槦浜?/p> //緇х畫鏇存柊 緇忚繃AekdyCoin鏁欏 鍙戠幇榪欎釜綆楁硶褰揳鍜宯涓嶄簰璐ㄧ殑鏃跺欎細(xì)姝?鍥犱負(fù)娌℃湁閫嗗厓 i*m-j涓嶈兘闅忎究鍑?/p> 浜庢槸榪炲寮鍙戜笉浜掕川綆楁硶濡備笅 璁炬煇璐ㄦ暟p鍦╝閲岀殑鎸囨暟鏄痑p 鍦╪閲岄潰鏄痭p 鍦╞閲岄潰鏄痓p 閭d箞褰搙寰堝ぇ ap*x蹇呯劧澶т簬np 榪欎釜鏃跺檅p蹇呴』涓嶅皬浜巒p 鍏墮嗗懡棰樹篃鎴愮珛 鍚屾椂 灝唍閲岄潰鐨刾鍏ㄩ儴闄ゆ帀 鍓╀笅鐨勭敱浜庡拰p浜掕川 鎵浠ュ乏杈筧錛宐鍙笉蹇呴櫎 鍙嶆鏈鍚巃^x-b涓瀹氭暣闄 鎵浠?鍏堝垽鏂璦鍜宯鐨勫叕鍏辮川鍥犳暟閲岄潰 鏈夋病鏈塨姣攏灝忕殑 鑻ュ皬蹇呮 鍚﹀垯鐩存帴灝唍闄ょ殑鍜宎浜掕川鍐嶅仛瀹岀牬 娉ㄦ剰鍒版瘡涓川鏁扮殑鎸囨暟鑲畾涓嶈秴榪?0 閭d箞褰搙澶т簬40浠ヤ笂鏂規(guī)硶蹇呯劧鎴愮珛 褰搙灝忕殑鏃跺?铏界劧緇忚瘉鏄庝篃鍙互鍖栦負(fù)abn浜掕川鎯呭喌 浣嗘槸涓嶅鐩存帴楠岃瘉 鎵浠ヤ笉綆′簡 鍒嗘瀽:璁鵑潚铔欒煩浜唊嬈?閭d箞灝辨湁(x+mk)-(y+nk)=p*L. 鍗硏-y+(m-n)k=p*L,鍗?m-n)*k≡(y-x) (mod L). 榪欎釜綰挎у悓浣欐柟紼嬫湁瑙e綋涓斾粎褰?span>gcd(m-n,L)|(y-x). 浠=m-n,b=L,c=y-x.鐢ㄦ墿灞曟鍑犻噷寰楄В鏂圭▼ax+by=c. 鍙互姹傚嚭鍘熸柟紼嬬殑涓涓В.濡備綍姹傛渶灝忔鏁存暟瑙e憿? 鍋囪鎴戜滑宸茬粡寰楀埌涓涓獂0,浠=gcd(m-n,L), 閭d箞鎵鏈夎В鍙互琛ㄧず涓簒=x0+k*L/d. 璁綥'=L/d. Xmin=(x0 mod L'+L') mod L'. WA涓ゆ錛?Ms錛屽洤錛岃繕鏈変竴嬈$紪璇戦敊璇紒錛侊紒 鎬葷粨錛氫唬鐮侊紝榪樻槸寰楀ぉ澶╁啓錛屼笁鏃ヤ笉緇冩墜鐢熴傝嚜宸卞鎯蟲兂錛屽鎬濊冩濊冩墠鑳芥彁鍗囪兘鍔涘搱銆?/p> 涓嶈鎬繪槸鍘葷湅鍒漢鐨勯瑙o紝瑕佹湁鑷繁鐨勬濊礬鍝堛?/p> 鏁拌錛岃繕寰楃戶緇湅錛岀戶緇銆傝鍚冮忔墠琛屻?br /> The easiest way to make the problem statement unusual is to omit it. This is an extremely convenient approach — you don’t have to maintain the statement in two languages or to worry that it might turn out to be ambiguous or too long or too scary. 690 people solved this problem, so evidently we can omit statements even in regular rounds :-) As for the problem itself, it required to sum the first number and the reverse of the second number. They say it’s better to see once than to hear ten times or to read a hundred times. In this problem we decided to check this and to replace the traditional textual statement with a single image. Same as in the previous problem, it did well — at least 645 participants recognized star numbers (sequence http://oeis.org/A003154 in OEIS), the numbers of balls needed to form a six-pointed start of certain size. After this one had only to code the formula — Sn = 6n(n−1) + 1. What does one do if the statement is unknown and the only source of information about the problem is the checker? Right — you just try all possible functions which convert 5 input values into 3 output values and see which of them fits :-) This problem finally has a statement! The trick is, it’s encoded. We decided to be kind to you and to use the simplest cipher possible — Caesar cipher (each letter is shifted the same number of positions in the alphabet). By a long stretch of imagination one could break the cipher by hand — observe frequent letters and short words, deduce possible values of shift and verify it against the rest of the message. A lazier one could Goog le for a tool like this one and get the decoded version semi-automatically. After cracking the statement the rest was almost easy — you had to find a prime whose reverse is a prime different from the original one (sequence http://oeis.org/A006567). 11184-th such number equals 999983, so one could do a brute-force check of all numbers in row. A special contest written by me and no special programming language? Impossible! I pulled myself up and made only 25% of all problems esoteric — that’s two. There really should be three but the third interpreter refused to cooperate. Maybe next time… What can one do if all he knows about the language is its compiler? Just run any code and see what the compiler says. In this case the compiler said “DO YOU EXPECT ME TO FIGURE THIS OUT?”, and Google should tell you immediately that the language in question is INTERCAL. The problem simplifies to figure out the dialect used and how to output “INTERCAL” in it. In Codeforces round #96 I gave a problem 133C - Turing Tape which explained the mechanism of string output in INTERCAL and asked to write a program which converted a string into an array of numbers which would print this string. Combine this knowledge with Hello, World! example and you get the program you need. Actually, that’s what I did to write the reference solution. The second esoteric problem had a Chef program as the statement. You had only to figure out what it does and do it in any regular language. It turns out that this program reads N followed by N numbers $a_1, a_2, …, a_N$ and calculated the sum i * ai. This one was much harder to guess but much easier to code. First two numbers were the start of a Fibonacci-like sequence, and the third one was the index of the required number in this sequence. 3. if n = 1 then STOP
4. if n is odd then n <-- 3n+1
5. else n <-- n/2
闂寰堟槑鐧斤紝涔嬪墠鍦╤du涓婁篃鍋氫簡錛岀粡楠岃繕鏄病鏈夊搰銆俉A浜嗗ソ澶氬ソ澶氭銆?br />1w鐨勬暟鎹緢寮憋紝鐩存帴鏆村姏褰撶劧鑳借繃銆?br />涓嶈繃100W灝變笉琛屼簡銆傝蹇嗗寲鎼滅儲(chǔ)DP鏄釜濂藉姙娉?br />鎴戞渶涔嬪墠鐨勫仛娉曞氨鏄繖涓紝鏁堟灉榪樼畻涓嶉敊銆?br />
姹傚嚭鎵鏈夌殑鍊煎悗灝辨槸鍖洪棿姹傛渶澶у間簡錛屾湁RMQ綆楁硶錛岀嚎孌墊爲(wèi)絳夐兘琛屻備笉榪囷紝鎴戦兘涓嶄細(xì)鍛錛侊紒錛侊紒錛侊紒錛侊紒
鏈楄鐨勬椂鍊欏氨鍋氫簡涓尯闂存渶鍊肩殑闂錛屽綋鏃舵湸绱犵畻娉曚竴鐩碬A錛宩h杈夌 qsort()涓涓嬶紝浠庡墠寰鍚庣粰AC浜嗐傦脊錛脊錛?br />
鏈鍚庤繕鏄氨鏄粏鑺傞棶棰樹簡錛屽儚杈撳嚭锝擄紝锝斻傛湁鍙兘锝擄紴锝旓紝杈撳嚭鍗存槸瑕佹寜鐓ц緭鍏ラ『搴忚緭鍑猴紒鏅曪紝灝辮繖鏍鳳擠錛′簡涓澶┿?br />鎬葷粨錛?br /> 緇嗚妭闂瑕佹敞鎰忥紒澶氭兂鎯沖叾浠栫畻娉曪紝姘撮涓嶆按鍛銆?br />
#include<string.h>
#include<math.h>
long long a[10005];
int GetC()
{
int i,t;
for (i=1;i<=10000 ;i++ )
{
t=i;a[i]=1;
while (t!=1)
{
a[i]++;
if (t&1)
t=3*t+1;
else
t/=2;
}
}
}
int main()
{
int s,t,i;
long long mm;
GetC();
while (scanf("%d%d",&s,&t)==2)
{
printf("%d %d ",s,t);
if (s>t)
i=s,s=t,t=i;
mm=a[s];
for (i=s;i<=t ;i++ )
mm=mm>a[i]?mm:a[i];
printf("%I64d\n",mm);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<math.h>
long long a[10005];
int GetC()
{
int i,t;
for (i=1;i<=10000 ;i++ )
{
t=i;a[i]=1;
while (t!=1)
{
a[i]++;
if (t&1)
t=3*t+1;
else
t/=2;
}
}
}
int main()
{
int s,t,i;
long long mm;
GetC();
while (scanf("%d%d",&s,&t)==2)
{
printf("%d %d ",s,t); //榪欎釜WA浜嗕竴嬈?br /> if (s>t) //榪欎釜WAl浜嗗ソ澶氭錛侊紒
i=s,s=t,t=i;
mm=a[s];
for (i=s;i<=t ;i++ )
mm=mm>a[i]?mm:a[i];
printf("%I64d\n",mm);
}
return 0;
}棰濓紝浠g爜榪樻槸娌℃湁鑷繁椋庢牸鍟娿傝繖浜涗釜鍑芥暟鍚嶈繕鏄偅涔堥毦鍙栧憿銆?br />
]]>棰樼洰澶ф剰錛氱粰瀹氫竴涓ぇ鏁存暟錛岃繖涓暟鏄袱涓礌鏁扮殑涔樼Н錛岀劧鍚庣粰瀹氫竴涓暟L錛屽鏋滆繖涓や釜绱犳暟涓湁涓涓瘮L灝忥紝灝辮緭鍑築AD錛涗笉鐒惰緭鍑篏OOD
楂樼簿搴︽眰妯★紝涓杈瑰姞涓杈規(guī)ā錛屼笉榪囧鏋滄槸100鎴栬?000榪涘埗榪欎簺錛岃娉ㄦ剰鍟︼紝濡?000榪涘埗 12345 搴旇涓?2 345榪欐牱錛屼笉瑕佸紕紼?23 45銆傛垜灝辨槸榪欐牱閿欑殑鍝︼紒錛侊紒
鍚屼綑妯″畾鐞嗭細(xì)http://hi.baidu.com/koomo007/blog/item/110cd6f58bc91964ddc47424.html
棰濓紝W(xué)A浜嗗緢澶氭鍝堬紝鍏堟槸娌℃湁鎯沖埌浠?0榪涘埗鍋氳TLE錛屽悗鏉ョ敤1000鏈夋悶閿欎簡錛侊紒錛?br />
鎬葷粨錛氬悇縐嶆柟娉曠畻娉曡鍚冮忔墠琛屽晩銆備笉鑳藉彧棰嗙暐澶ф銆傝綆楀ソ鏃墮棿絀洪棿澶嶆潅搴︼紒
WA 3嬈★紝1嬈C 954MS
#include<string.h>
#include<math.h>
char ch[155];
int prime[500005],b[1010000],a[155];
int n,tot,m;
int get_mod(int p)
{
int i,ans;
ans=0;
for (i=1; i<=m ; i++ )
ans=(ans*1000+a[i])%p;
return ans;
}
int main()
{
int i,j,k,t,len;
memset(b,0,sizeof(b));
i=2;
tot=0;
while (1)
{
while (b[i]) i++;
prime[++tot]=i;
j=i;
if (i>1000000)
break;
while (j<=1010000)
{
b[j]=1;
j+=i;
}
}
while (scanf("%s%d",&ch,&n)==2&&n)
{
m=strlen(ch);
i=0;
k=0;
t=m%3;
if (t>0)
{
a[++k]=0;
for (i=0; i<t ; i++ )
a[k]=a[k]*10+ch[i]-48;
}
while (i<m)
{
t=3<m-i?3:m-i;
a[++k]=0;
for (j=i; j<i+t ; j++ )
{
a[k]=a[k]*10+ch[j]-48;
}
i+=t;
}
m=k;
i=1;
while (i<=tot&&prime[i]<n&&get_mod(prime[i]))
i++;
if (prime[i]<n)
printf("BAD %d\n",prime[i]);
else
printf("GOOD\n");
}
return 0;
}
]]>
鐑韓璧涜鏄幓騫存湕璁殑楂樼駭緇勭殑棰樼洰錛屽懙鍛碉紝铏界劧榪樻湁涓棰樻病鏈夊仛鍑烘潵錛屼笉榪囷紝榪樻槸鍘繪彁浜や簡yes浜嗗洓涓傘傘備腑閫旂綉緇滃嚭浜嗙偣闂錛屾劅瑙夊崕涓虹殑榪樻槸娌℃湁緇忛獙錛屽懙鍛碉紝絎竴嬈″槢銆?br />灞呯劧閫氱煡璇撮珮綰х粍棰樼洰鍏ㄩ儴鏄嫳璇紝鏅曚簡錛屽緱鎵句釜緲昏瘧鍟娿傚搱鍝堬紝鐜嬫儫浼婂悓瀛﹀綋鐒舵槸棣栭夊暒錛屼笉鎯砲xj濂瑰幓琚墦鍑諱簡^.^
鎯熶紛鍚屽榪樼湡鏄粰鍔涳紝鍝堝搱錛屼笂嬈¤仈璧涘氨杞繪澗铏愬満錛岃繖嬈′竴璧峰績鎬佸緢濂藉緢濂絕
棰濓紝姣旇禌錛屽績鎬佸緢閲嶈鍝︺?br />
5涓鐩紝涔嬪墠鎴戝氨緇欏畨鎺掍簡鍏堢湅棰樼洰鐭殑棰樼洰銆傜涓涓鐩槸宸ㄩ暱鐨勬弿榪板晩錛屾灉鏂湅鍏朵粬鐨勩?br />鎴戞嫞浜嗕釜鏁版嵁姣旇緝綆鍗曠殑C棰樼湅浜嗙湅錛屽搸錛岃椽蹇冿紝so easy銆傝繕鐢ㄤ笂浜嗘垜鍒氬垰鍐欑殑qsort.
絎竴涓彁浜ゅ氨yes浜嗭紝鍛靛懙錛岀涓涓搱銆傚簲璇ヤ笉瓚呰繃15min鍚э紝鎸虹埥鐨勩?br />
鎯熶紛鍚屽緇欎簡鎴態(tài)棰橈紝鎻忚堪瀹屼簡錛屽懙鍛碉紝dp鍢涳紝鏂圭▼涓涓嬪瓙灝卞嚭鏉ヤ簡銆傚啓瀹屾牱渚嬪氨榪囦簡錛屾灉鏂彁浜ゃ傝繑鍥炰簡涓狽O錛屾兂鍒拌偗瀹氭槸瓚婄晫婧㈠嚭浜嗭紝int涓嶅銆傛崲long long錛岀粨鏋滅紪璇戦敊璇紝鍝庯紝鏈嶅姟鍣ㄤ笉琛屽晩銆傚彧鏈夋崲double浜嗭紝鍛靛懙錛寉es浜嗐備笉榪囧紑鍝ヨdouble鍚庨潰灝變笉綺劇‘浜嗭紝榪樻尯涓嶆斁蹇冪殑錛岀湅鏉ユ槸鎯沖浣欎簡銆傚緱濂藉ソ鐮旂┒c鎵嶈鍟?
鍏村鍏村錛屼袱涓錛屼笉鎬曚笉琚檺浜嗐傜幇鍦ㄥぇ姒傝繃鍘?0min浜嗗惂錛?br />
鐒跺悗鏄疍棰橈紝鎯熶紛鍚屽璇翠篃鏄釜dp錛屽搱鍝堝搱錛?1涓茶鏁伴棶棰橈紝褰撶劧dp鍟︺?br />涓嶈繃榪欓噷綰犵粨浜嗘尯涔咃紝鍘熸潵鑴戜腑涓寮濮嬬殑閭d釜鏂圭▼鏄湁闂鐨勶紝綰犵粨鐨勬尯涔呫備互鍚庡仛dp錛岃繕鏄緱鍏堝啓濂芥柟紼嬪拰鐘舵佽〃紺猴紝涓嶈鍏堝啓浠g爜銆?br />
鏍蜂緥榪囦簡錛屽樋鍢匡紝鎴戣仾鏄庝簡涓嬶紝媯(gè)鏌ヤ簡鐪嬬湅鏈夋病鏈夎秺鐣岋紝鍛靛懙錛屾灉鐒惰秺鐣屾孩鍑轟簡銆傛灉鏂湴鎹簡double銆?br />涓涓媦es!!鍝堝搱錛?涓鐩紝宸茬粡榪戒笂杈夊摜鍟︼紝80min榪囧幓銆?br />鎯熶紛鍚屽闂簡闂紑鍝ワ紝鍛靛懙錛宱nly 1 yes錛岄錛屽紑鍝ユ病鍙戞尌濂姐?br />
鍚庨潰灝辨?zhèn)叉儴浜嗗Q屼袱涓崐澶氬皬鏃跺仛鏈鍚庝竴棰橈紝bfs錛岄偅涓姸鎬佸拰杞Щ鍟婏紝涓寮濮嬪氨娌℃湁璁捐濂斤紝鑰冭檻鍏ㄩ潰錛岀粨鏋滆竟鍐欒竟璁捐錛岃嚜宸辮兘鍔涜繕鏄笉澶燂紝嫻垂浜嗕笉灝戞椂闂達(dá)紒鍚庢潵鍙堝嚭闂鍦ㄦ柟鍚戜笂錛屽搸錛屾?zhèn)叉儴浜嗗Q宐fs錛宒fs閮藉簲璇ユ兂鎯蟲柟鍚戝晩錛堝瓧鍏稿簭榪欎簺錛夈傜瓑鎼炲畾榪欎簺錛屽氨娌℃湁鍓╀笅鏃墮棿鍟︼紝鏈鍚庡幓鐪嬪彂鐜拌嚜宸卞眳鐒墮槦鍒楀紑灝忎簡錛屼箣鍓嶇畻鐨?錛佷笉瀵癸紝搴旇鏄?錛佸晩錛屽潙鐖瑰潙鐖瑰憿銆傘傘傘傘傘?br />
絎竴棰樺氨涓嶈浜嗭紝鎯熶紛鍚屽閮芥病鏈夋悶娓呮棰樻剰錛屼富瑕佹槸杈撳嚭閭d釜琛ㄧず娌℃湁鎼炴槑鐧斤紝鍛靛懙鍛碉紝涓嶈繃鎯蟲兂鍏跺疄涔熸槸涓姸鎬佸帇緙╃殑綆鍗曢鐩?br />
5涓鐩紝AC3涓紝閬楁喚涓涓傝繖嬈″崕涓烘澂綆楁槸涓儹韜惂錛岀渷璧涙墠鏄噸鐐癸紒錛侊紒
A錛氱姸鎬佸帇緙?br />B:dp
C:璐績
D:dp
E錛歜fs錛堝瓧鍏稿簭錛?br />
]]>
棰濓紝鎯沖埌浜?*n+2,榪欎釜鏁版ā3*n錛屽氨鏄墿涓嬬殑閭d袱涓暟妯?*n浜嗭紝鐩存帴榪欐牱涔熸槸娌℃湁鍔炴硶鏉ュ鐞嗙殑銆傝鎬庝箞鏀硅繘濂藉憿錛屽緱鍐嶇爺絀剁爺絀禴……^
寮傛垨榪愮畻錛屽懙鍛碉紝杈夊摜鎯沖埌榪欎釜鍙互銆傚棷錛屼篃鏄紝婕旂畻浜嗕竴涓嬶紝紱繪暎閲屽榪囩殑鍑犱釜榪愮畻鍙互瀹炵幇鎶奱@a@a榪欑緇欏鐞嗘帀鎴愬崟浣嶅厓鐨?#8230;…榪欓噷鎺ョ潃鎯蟲兂鎵嶈銆?br />
鍘熸潵浣嶈繍綆楀疄鐜板彲浠ュ垎瑙e埌2榪涘埗鏉ュ仛錛屾ā鎷熴傚搱鍝堬紝鐪熸槸濂戒笢瑗褲?br />a[],b[],c[][]錛岃繖閲宎[i]琛ㄧず榪欎簺鏁板垎瑙e埌絎琲浣嶄笂鐨勭瘡鍔狅紝妯?涔嬪悗灝辨槸閭d袱涓暟鍦ㄨ繖涓綅涓婄殑鍊間簡銆俢[i][j]琛ㄧずi浣嶅拰j浣嶆槸鍚﹀湪鏌愪釜鏁頒腑銆?br />榪欐牱涔嬪悗濡傛灉a[i]==2閭h繖涓や釜鏁伴兘鍦ㄨ繖涓綅涓婃湁鍒嗚В錛屽悇鑷瘡鍔犱笂鍘伙紝
濡傛灉a[i]==1灝卞緱璁ㄨ浜嗭紝濡傛灉璁板綋鍓嶅垎瑙g殑鏁板湪涓涓湁鍒嗚В鐨勪綅緗槸flag錛屽垯濡傛灉c[flag][i]==1閭d箞鍙互鐭ラ亾i浣嶄篃鏄繖涓暟鐨勫垎瑙o紙ps,榪欓噷c[flag][i]涓嶄細(xì)涓?鐨勶級(jí)
棰濓紝鏈榪戝湪鐪嬬兢璁轟粈涔堢殑錛屾兂鍒頒竴涓鏄犲皠錛堝弻灝勶級(jí)錛岃繖浜涗釜濂界悊璁鴻繕鏄尯鏈夌敤鐨勫搱銆傘傘?br />
jh鏄敤浜唖鍜宻^2鍒嗗埆鍦版槧灝勮繃鍘伙紝榪欐牱綆楀嚭鏉+y=t1,x^2+y^2=t2,榪欎釜鏂圭▼濂借В鐨勩?br />
鎬葷粨錛?br /> 浠ュ悗鍋氶瑕佺湅鐪嬫暟鎹寖鍥達(dá)紝鏃墮棿絀洪棿銆傚厛璁捐濂界畻娉曪紝鍏堜及璁″ソ澶嶆潅搴︽墠琛岋紒錛?br /> hdu涓婁竴嬈C錛岃繍琛屼簡1000+Ms.涓嶇煡閬撻偅涓?Ms鐨勬槸鎬庝箞鍑烘潵緇撴灉鐨勶紝姹傝В錛?br />緹よ禌AC浠g爜錛氾紙絎竴縐嶆柟娉曪級(jí)![]()
hdu AC浠g爜錛氾紙絎簩縐嶆柟娉曪級(jí)
#include<string.h>
#include<math.h>
long long x,y;
int calc(int a[],long long s)
{
int i;
i=0;
while (s)
{
i++;
if (s%2==1)
{
a[i]++;
}
s=s/2;
}
return 0;
}
int main()
{
int t,i,j,n;
int a[70],b[70];
long long x,y,s;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for (i=1; i<=n ; i++ )
{
scanf("%I64d",&s);
calc(a,s);
calc(b,s*s);
}
for (i=1; i<=65 ; i++ )
a[i]%=3;
x=0;
for (i=65; i>=1 ; i-- )
{
x*=2;
x+=a[i];
}
for (i=1; i<=65 ; i++ )
b[i]%=3;
y=0;
for (i=65; i>=1 ; i-- )
{
y*=2;
y+=b[i];
}
printf("%.0lf %.0lf\n",(double)(x-sqrt((double)2*y-x*x))/2.0,(double)(sqrt((double)2*y-x*x)+x)/2.0);
}
return 0;
}
棰濓紝C寰堝急錛屽緱濂藉ソ鐪嬬湅Brian W.Kernighan鍜孌ennis M. Ritchie鐨勩奀 Programming Language銆嬨傚啀澶氫簡瑙d簡瑙g紪璇戝櫒鍜岀紪璇戝師鐞嗘墠琛屽晩
]]>
鍐欎簡涓澶╀簡錛屽厛鏄qsort()鍐欐垚qsrot()緇欒繍琛岄敊璇簡涓澶╋紝鏅氫笂鍙戠幇閿欒浜嗙畻娉曞張鍑轟簡闂銆傚搸鍝庯紝涓嶈鍛銆傚懆鏈殑鍗庝負(fù)錛岃刀绱х殑錛屽埛鍑犱釜棰樺啀璇達(dá)紒錛侊紒
鍘嬪姏灞卞ぇ鍝堬紒鍛靛懙錛屽績鎬佹渶閲嶈錛屾病浜嬫病浜嬶紝寮鏈楄眮杈懼氨琛屻?br />
]]>
鍒氬垰瀛︿簡鐐規(guī)暟璁猴紝涔熷ソ鍑犲ぉ娌℃湁鍐欎唬鐮佷簡錛岀敓鐤忎簡涓嶅皯錛屾繪槸鏈夐敊璇紝緙栬瘧涓▼搴忔庝箞閮介偅涔堢籂緇撳晩錛岀湅鏉ユ按騫沖疄鍦ㄦ槸宸晩錛侊紒
綰挎у悓浣欙紝鏂圭▼榪樻槸寰堝ソ灝辨瀯閫犲嚭鏉ヤ簡錛宔xtended_euclid錛屼腑鍥藉墿浣欏畾鐞嗭紝鍙槸鍚庨潰鍗翠笉鎸囧鎬庝箞姹傛渶灝忕殑鏁存暟浜嗭細(xì)
鐪嬩簡鐪嬪ぇ鐗涚殑棰樿В錛屽師鏉ヨ繖鏍峰晩錛岃嚜宸辨暟璁鴻繕寰楀瀛﹀鎵嶈錛屽鎯蟲兂鍟婏細(xì)
#include<string.h>
#include<math.h>
long long c,d;
long long gcd_ext(long long a,long long b)
{
long long gcd,t;
if (!b)
{
c=1;d=0;
return a;
}
gcd=gcd_ext(b,a%b);
t=c;c=d;d=t-a/b*d;
return gcd;
}
int main()
{
long long x,y,m,n,L,a,b,gcd;
while (scanf("%I64d%I64d",&x,&y)==2)
{
scanf("%I64d%I64d%I64d",&m,&n,&L);
a=m>n?m-n:n-m;
b=m>n?y-x:x-y;
gcd=gcd_ext(a,L);
L=L/gcd;
if (b%gcd==0)
printf("%I64d\n",((c*b/gcd)%L+L)%L);
else
printf("Impossible\n");
}
return 0;
}
]]>
#include<string.h>
#include<math.h>
int a=10000,b,c=8400,d,e,f[8401],g;
main()
{
for(; b-c;)
f[b++]=a/5;
for(; d=0,g=c*2; c-=14,printf("%.4d",e+d/a),e=d%a)
for(b=c; d+=f[b]*a,f[b]=d%--g,d/=g--,--b; d*=b);
}
鍒板簳鏄粈涔堢畻娉曞憿錛屽緱鐮旂┒鐮旂┒錛?img src ="http://www.shnenglu.com/ArcTan/aggbug/170161.html" width = "1" height = "1" />
]]>
涓殑G棰?br />
緹ら噷鎺ㄨ崘鍋氬仛榪欎釜錛岀湅浜嗙湅錛屼笉鐭ラ亾鎬庝箞寤哄浘銆?br />鐪焥,鐪嬩簡log涔熻繕鏄病鏈夊弽搴旇繃鏉ワ紝
鍝庡搸錛宭og(ai/bj)=log(ai)-log(bj)鍢涳紝榪欐牱灝卞緩鍥句簡鍟婏紒錛侊紒錛侊紒
#include<string.h>
#include<math.h>
#define Max 0xfffffff
int N,M;
int que[1550000],into[805],vis[805];
double dis[805],map[805][805];
int spfa()
{
int head,tail,now,i;
memset(into,0,sizeof(into));
for (i=1; i<=N ; i++ )
que[i]=i,vis[i]=0,dis[i]=Max;
head=0;tail=N;que[0]=0;dis[0]=0.0;
while (head<=tail)
{
now=que[head++];
vis[now]=1;
into[now]++;
if (into[now]>4)
return 0;
for (i=1; i<=N ; i++ )
if (dis[now]+map[now][i]<dis[i])
{
dis[i]=dis[now]+map[now][i];
if (vis[i])
que[++tail]=i,vis[i]=0;
}
}
return 1;
}
int main()
{
int i,j;
double L,U,a;
while (scanf("%d%d%lf%lf",&N,&M,&L,&U)==4)
{
for (i=0; i<=N+M ; i++ )
for (j=0; j<=N+M ; j++ )
map[i][j]=Max;
for (i=0; i<=N+M ; i++ )
map[0][i]=0.0;
U=log(U);L=log(L);
for (i=1; i<=N ; i++ )
for (j=1; j<=M ; j++ )
{
scanf("%lf",&a);
map[j+N][i]=U-log(a);
map[i][j+N]=log(a)-L;
}
N=N+M;
puts(spfa()?"YES":"NO");
}
return 0;
}
寤虹珛妯″瀷寰堥噸瑕佸搰錛侊紒
鍥捐鐨勬渶鐭礬錛屽ソ澶氫笢瑗垮憿錛屽緱濂藉ソ瀛﹀鍟婏紝spfa鏄釜濂戒笢瑗褲備互鍚庤澶氬綆楁硶澶氱湅璁烘枃浜嗭紒
spfa錛屽彲浠ュ垽鏂礋鏉冨洖璺搱銆傝繖涓鐩瘮杈冨急錛?嬈″氨鍙互浜嗐傚娓竤qrt(|v|)鐨勶紝n褰撶劧鏄竴涓笂鐣屻?img src ="http://www.shnenglu.com/ArcTan/aggbug/170155.html" width = "1" height = "1" />
]]>
璇ュ瀛︽敼榪涚殑鍗曠函鍨嬫硶浜嗐?br />
綰挎ц鍒掗棶棰樿繕鏄湁寰堝鐢ㄧ殑錛屾槸涓ソ妯″瀷錛侊紒錛?br />
#include<string.h>
#include<math.h>
#define inf 10000000.0
int n,m;
int g[1005],q[1005],p[1005];
double b[1005],c[1005],x[1005],a[1005][1005];
//********鏁版嵁杈撳叆銆佸垵濮嬪寲*************
int init()
{
int i,j;
//********鏁扮粍鍒濆鍖?*********
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
memset(x,0,sizeof(x));
memset(q,0,sizeof(q));
printf("璇瘋緭鍏ュ崟綰瀷琛ㄧ殑鏍囧噯鍨?\n");
//********杈撳叆鏁版嵁************
scanf("%d%d",&m,&n);
for (i=1; i<=n ; i++ )
scanf("%lf",&c[i]);
for (i=1; i<=n ; i++ )
scanf("%d",&p[i]);
for (i=1; i<=m ; i++ )
{
for (j=1; j<=n ; j++ )
scanf("%lf",&a[i][j]);
scanf("%lf",&b[i]);
}
//**********鍒濆鍖栧崟綰瀷琛?***
for (i=1; i<=m ; i++ )
g[i]=i,q[i]=1,a[i][n+1]=b[i],x[i]=b[i];
for (j=1; j<=n ; j++ )
a[m+1][j]=c[j];
for (j=n+1; j>m ; j-- )
{
for (i=1; i<=m ; i++ )
a[m+1][j]-=c[i]*a[i][j];
}
}
//**********緇撴灉杈撳嚭********************
int print(int result)
{
int i;
double sum;
if (result==-1)
{
printf("鏃犲彲琛岃В\n");
return ;
}
if (result==-2)
{
printf("鏃犵晫瑙n");
return ;
}
if (result==-3)
{
printf("鏃犵┓澶氭渶浼樿В銆傚叾涓竴涓槸錛歕n");
sum=0.0;
for (i=1; i<=n ; i++ )
sum+=x[i]*c[i];
for (i=1; i<n ; i++ )
printf("%.4lf ",x[i]);
printf("%.4lf\n",x[n]);
return ;
}
printf("鏈夋渶浼樿В錛歕n");
sum=0.0;
for (i=1; i<=n ; i++ )
sum+=x[i]*c[i];
printf("%.4lf\n",sum);
for (i=1; i<n ; i++ )
printf("%.4lf ",x[i]);
printf("%.4lf\n\n",x[n]);
return ;
}
//***********媯(gè)鏌ュ崟綰瀷琛?**************
int check()
{
int i,j,flag,flg,mj;
double max;
flag=0;
flg=0;
for (j=1; j<=n ; j++ )
{
if (a[m+1][j]>0.0)
{
flag=1;
max=0.0;
for (i=1; i<=m ; i++ )
if (a[i][j]>max)
max=a[i][j],mj=j;
if (max>0.0)
flg=1;
}
}
if (!flag)
{
for (i=1; i<=m ; i++ ) //鍒ゆ柇鏄惁鏃犲彲琛岃В
{
if (p[g[i]]&&a[i][n+1]!=0.0)
return -1;
}
for (j=1; j<=n ; j++ ) //鍒ゆ柇鏄惁鏈夋棤絀峰鏈浼樿В
if (!q[j]&&a[m+1][j]==0.0)
return -3;
return 0;//鍞竴鏈浼樿В
}
if (!flg)
return -2;//鏃犵晫瑙?/span>
return mj;//鎵懼埌鏈澶х殑閭d釜a[m+1][j]浣滀負(fù)鎹㈠叆鍙橀噺
}
//*********鎵懼埌鏈灝忕殑閭d釜鏁?************鎬繪槸鑳芥壘鍒扮殑錛燂紵錛燂紵
int f_min(int r)
{
int i,mi;
double min;
min=inf;
for (i=1; i<=m ; i++ )
if (a[i][r]!=0.0&&a[i][n+1]/a[i][r]>0&&a[i][n+1]/a[i][r]<min)
min=a[i][n+1]/a[i][r],mi=i;
printf("%.4lf ",min);
return mi;//紜畾涓烘崲鍑哄彉閲?/span>
}
//********guass娑堝厓娉曡繘琛岃凱浠?**********
int guass(int k,int r)
{
int i,j;
for (j=n+1; j>=1 ; j-- ) //琛屽彉鎹?/span>
if (j!=r)
a[k][j]/=a[k][r];
a[k][r]=1.0;
for (i=1; i<=m+1 ; i++ ) //姣忎竴琛岃繘琛屽彉鎹?/span>
if (i!=k)
{
for (j=1; j<=n+1 ; j++ )
if (j!=r)
a[i][j]-=a[k][j]*a[i][r];
a[i][r]=0.0;
}
q[g[k]]=0;
g[k]=r;
q[r]=1;
memset(x,0,sizeof(x));
for (i=1; i<=m ; i++ )
x[g[i]]=a[i][n+1];
}
int work()
{
int i,j,r,k;
while (1)
{
for (i=1; i<=m+1 ; i++ )
{
for (j=1; j<=n+1 ; j++ )
printf("%.4lf ",a[i][j]);
printf("%d\n",g[i]);
}
for (j=1; j<=n ; j++ )
printf("%.4lf ",x[j]);
printf("%.4lf\n",x[j]);
r=check();
if (r<=0)
return r;
k=f_min(r);
printf("%d %d\n\n",k,r);
guass(k,r);
}
}
int main()
{
int result;
init();
result=work();
print(result);
return 0;
}
鏈夋椂闂村緱鍘籶oj錛寊oj涓婃壘鎵劇嚎鎬ц鍒掔殑棰樼洰鏉ヤ笅鍐欏啓銆傚樋鍢匡紝
]]>
bfs:閮芥槸浜涘熀鏈殑綆楁硶浜嗭紝鍚勭bfs鍐欎簡涓嶅皯鍟︺?br />榪欎釜棰樼洰涔熸尯綆鍗曠殑錛屼富瑕佹槸閭e嚑涓漿縐繪柟鍚戣繕鏄浼樺寲涓嬪ソ鍐欙紝瑙夊緱鑷繁鍐欏緱榪樺彲浠ュ搱錛?br />鍢垮樋錛?br />bfs:0ms
#include<string.h>
#include<math.h>
int a[2],c,head,tail;
int que[10005][2],pre[10005],p[10005],vis[105][105],ans[10005];
int check()
{
if (que[tail][0]==c||que[tail][1]==c)
return 1;
return 0;
}
int Fill(int i)
{
int t=tail+1;
que[t][0]=que[head][0];
que[t][1]=que[head][1];
que[t][i-1]=a[i-1];
if (!vis[que[t][0]][que[t][1]])
{
vis[que[t][0]][que[t][1]]=1;
p[t]=i;
pre[t]=head;
return 1;
}
return 0;
}
int Drop(int i)
{
int t=tail+1;
que[t][0]=que[head][0];
que[t][1]=que[head][1];
que[t][i-1]=0;
if (!vis[que[t][0]][que[t][1]])
{
vis[que[t][0]][que[t][1]]=1;
p[t]=2+i;
pre[t]=head;
return 1;
}
return 0;
}
int Four(int i,int j)
{
int min,t=tail+1;
min=(que[head][i-1])<(a[j-1]-que[head][j-1])?(que[head][i-1]):(a[j-1]-que[head][j-1]);
que[t][j-1]=que[head][j-1]+min;
que[t][i-1]=que[head][i-1]-min;
if (!vis[que[t][0]][que[t][1]])
{
vis[que[t][0]][que[t][1]]=1;
p[t]=4+i;
pre[t]=head;
return 1;
}
return 0;
}
int bfs()
{
int i,tmp;
memset(vis,0,sizeof(vis));
head=0;
tail=1;
que[1][0]=0;
que[1][1]=0;
vis[0][0]=1;
pre[1]=0;
p[1]=0;
while (head<tail)
{
head++;
tmp=1;
for (i=1; i<=2 ; i++ )
{
if (Fill(i))
tail++;
if (check())
return tail;
if (Drop(i))
tail++;
if (check())
return tail;
if (Four(i,i+tmp))
tail++;
if (check())
return tail;
tmp=-1;
}
}
return 0;
}
int print(int k)
{
int i;
if (!k)
{
printf("impossible\n");
return 0;
}
i=0;
while (k)
{
ans[++i]=p[k];
k=pre[k];
}
printf("%d\n",i-1);
for (k=i-1; k>=1 ; k-- )
{
if (ans[k]<=2)
{
printf("FILL(%d)\n",ans[k]);
continue;
}
if (ans[k]<=4)
{
printf("DROP(%d)\n",ans[k]-2);
continue;
}
if (ans[k]==5)
printf("POUR(1,2)\n");
else
printf("POUR(2,1)\n");
}
return 0;
}
int main()
{
int k;
scanf("%d%d%d",&a[0],&a[1],&c);
if (c>a[0]&&c>a[1])
k=0;
else
k=bfs();
print(k);
return 0;
}
榪欏嚑澶╃殑bfs錛宒fs錛岄兘鏄涓嬈″氨AV錛屾尯鐖界殑錛屽樋鍢褲?br />澶氬啓鍐欐伓蹇冪殑浠g爜錛屼互鍚庡氨涓嶆伓蹇冧簡錛屽搱鍝堛?br />
寰堢撼闂鳳紝閭d簺鐢ㄥ緢灝戝唴瀛樼殑鏄庝箞鍋氬埌鐨勫憿錛熺湅鏉ヨ嚜宸辮繕鏄緢寮卞晩锝烇綖锝?br />
]]>
鏄劇劧鐨勬渶澶х嫭绔嬮泦錛屾垜鏅曞晩錛屾渶澶у洟娌℃湁瀛﹀ソ鍟婏紝娌℃湁鐪熸鐞嗚В娓呮
鍝庡搸
妯$増棰橈紝鏈澶х嫭绔嬮泦錛?br />
#include<string.h>
#include<math.h>
int map[100][100],x[100],b[100];
int n,m,max,now;
int dfs(int i)
{
int j,flag;
if (i>n)
{
for (j=1; j<=n ; j++ ) x[j]=b[j];
max=now;
return 0;
}
flag=1;
for (j=1; j<i ; j++ )
if (b[j]&&map[i][j]) //榪欓噷濡傛灉鏀逛負(fù)錛乵ap[i][j]灝辨槸姹傛渶澶у洟浜嗐傘傘傘?br /> {
flag=0;
break;
}
if (flag)
{
b[i]=1;
now++;
dfs(i+1);
now--;
b[i]=0;
}
if (now+n-i>max)
{
b[i]=0;
dfs(i+1);
}
}
int main()
{
int i,j,t,x1,x2,flag;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
memset(map,0,sizeof(map));
for (i=1; i<=m ; i++ )
{
scanf("%d%d",&x1,&x2);
map[x2][x1]=map[x1][x2]=1;
}
max=0;now=0;
dfs(1);
printf("%d\n",max);
flag=0;
for (i=1; i<=n ; i++ )
if (x[i])
{
if (flag)
printf(" ");
printf("%d",i);
flag=1;
}
printf("\n");
}
return 0;
}
]]>
bfs:鍒氬垰鎷垮埌鎯蟲妸鎵鏈夋暟緇欑敤瀛楃涓蹭繚瀛橈紝榪欐牱鏈澶氬彲鏈?00涓?1鍛€?br /> 涓鐩撮兘瑙夊緱榪欐牱鏈寸礌鐨勭畻娉曞緢鎭跺績錛屽氨鍘誨悆楗幓浜嗭紝鎴戝殦錛?2鐐瑰悆鏃╅キ銆?br /> 紿佺劧鎯沖埌鍏跺疄鎴戠殑涓插彲浠ue[]閲屽瓨0鍜?鍢涳紝鐒跺悗绱㈠紩涓涓嬪氨濂戒簡浜庢槸涔庯紝琛屼簡錛屽樋鍢褲傝繖鏍烽掓帹榪囧幓鐨勶紝鍏跺疄搴旇鏄彲浠ユ暣鍑轟簡dp鐘舵佽漿縐繪柟紼嬬殑鍝堬紝絳変細(xì)鎯蟲兂鍛?br /> bfs:
32MS
#include<string.h>
#include<math.h>
int n;
int que[1000005],pre[1000005],q[1000005],ans[205];//que[] 0銆?錛宷[]褰撳墠浣欐暟錛宲re[]鍓嶉┍銆?br />int bfs()
{
int head,tail,now,next,i;
head=0;tail=1;que[1]=1;pre[1]=0;q[1]=1;
while (head<tail)
{
now=q[++head]*10;
for (i=0;i<=1 ;i++ )
{
next=now+i;
tail++;
que[tail]=i;
q[tail]=next%n;
pre[tail]=head;
if (!q[tail])
return tail;
}
}
}
int main()
{
int i,k;
while (scanf("%d",&n)==1&&n)
{
i=bfs();
k=0;
while (i)
{
ans[++k]=que[i];
i=pre[i];
}
for (i=k;i>=1 ;i-- )
printf("%d",ans[i]);
printf("\n");
}
return 0;
}![]()
]]>171A - Mysterious numbers - 1
171B - A star
171D - Broken checker
171F - ucyhf
![]()
171E - UNKNOWN LANGUAGE
PLEASE DO ,1 <- #8 DO ,1 SUB #1 <- #110 PLEASE DO ,1 SUB #2 <- #32 DO ,1 SUB #3 <- #72 DO ,1 SUB #4 <- #136 DO ,1 SUB #5 <- #88 DO ,1 SUB #6 <- #136 DO ,1 SUB #7 <- #64 DO ,1 SUB #8 <- #80 PLEASE READ OUT ,1 PLEASE GIVE UP171C - A Piece of Cake
171G - Mysterious numbers - 2
絎竴嬈″仛CF錛岀湅鏉ユ槸娌℃湁閫夊ソ鏃墮棿鍟婏紝鍛靛懙錛孉pril Fools Day錛屾妸鎴戝ū涔愭剼浜嗐?br />緹や富璇磋繖鏄釜鏅烘収鐨勬瘮璧涳紝鎴戞壙璁わ紝鑷繁鏅哄晢涓嶈涓嶈~~~~
A錛?br />![]()
![]()
![]()
![]()
![]()
E鍜孎琛ㄧず涓嶄細(xì)鍟婏紝鍐嶇爺絀剁爺絀跺惂銆傚急鐖嗕簡~~~~
緹や富紜疄寰堝帀瀹沖憖錛岀湅鏉ヤ粖騫村張鏋滄柇浼?xì)琚檺浜嗐?br />
鎯寵薄鍔涗笉琛屽憖錛?img src ="http://www.shnenglu.com/ArcTan/aggbug/169845.html" width = "1" height = "1" />
]]>