锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产一区二区电影,国产亚洲色婷婷久久99精品91 ,日本精品久久久久中文字幕8http://www.shnenglu.com/cxiaojia/category/18042.html鍘氬痙 鍗氬 姹傜湡 鑷沖杽 The bright moon and breezezh-cnMon, 07 May 2012 13:29:31 GMTMon, 07 May 2012 13:29:31 GMT60Ural 1880. Psych Up's Eigenvalues錛堟按棰橈級http://www.shnenglu.com/cxiaojia/archive/2012/05/07/173885.htmlC灝忓姞C灝忓姞Mon, 07 May 2012 03:15:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/05/07/173885.htmlhttp://www.shnenglu.com/cxiaojia/comments/173885.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/05/07/173885.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/173885.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/173885.html

棰樻剰錛?span style="font-size: 10pt; ">鏈?/span>3涓漢

姣忎釜浜烘湁n涓壒寰佸?/span>(1 ≤ n ≤ 4 000)

姹傛瘡涓漢閮芥湁鐨勭壒寰佸兼湁鍑犱釜錛?/span>(鐗瑰緛鍊?/span> ≤ 10^9)

鍒嗘瀽錛氭垜鎶婃墍鏈夌殑鏁版嵁鏀懼埌涓涓暟緇勯噷鎺掑簭錛屾湁榪炵畫涓変釜鐩稿悓鐨勮瘽灝辨槸涓涓叡鍚岀壒寰併?br />

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int arr[12003];
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    for(i=0;i<n;++i)
    {
        scanf("%d",&arr[i]);
    }
    scanf("%d",&n);
    n+=i;
    for(;i<n;++i)
    {
        scanf("%d",&arr[i]);
    }
    scanf("%d",&n);
    n+=i;
    for(;i<n;++i)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n);
    int cnt=0;
    for(int j=0;j<n-2;++j)
    {
        if(arr[j]==arr[j+1]&&arr[j+1]==arr[j+2])
        {
            ++cnt;
        }
    }
    printf("%d\n",cnt);
    return 0;
}



C灝忓姞 2012-05-07 11:15 鍙戣〃璇勮
]]>
Ural 1787. Turn for MEGA錛堟按棰橈級http://www.shnenglu.com/cxiaojia/archive/2012/05/07/173883.htmlC灝忓姞C灝忓姞Mon, 07 May 2012 02:51:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/05/07/173883.htmlhttp://www.shnenglu.com/cxiaojia/comments/173883.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/05/07/173883.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/173883.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/173883.html

棰樻剰錛?/span>k涓烘瘡鍒嗛挓鍙互閫氳鐨勬渶澶ц濺杈嗐備竴鍏辨湁n涓垎閽燂紝緇欏嚭姣忓垎閽熸柊鍑虹幇鐨勮濺杈嗘暟錛岄棶榪囦簡n鍒嗛挓鍚庤繕鍓╀笅澶氬皯杈嗚濺娌℃湁閫氳銆?/span>

鍒嗘瀽錛氱洿鎺ユā鎷熷氨鍙互浜嗐?br />

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
    int k,n;
    scanf("%d %d",&k,&n);
    int sum=0,val;
    for(int i=0;i<n;++i)
    {
        scanf("%d",&val);
        sum+=val;
        sum=sum>k?sum-k:0;
    }

    printf("%d\n",sum);


    return 0;
}



C灝忓姞 2012-05-07 10:51 鍙戣〃璇勮
]]>
Uestc 1652 Grab a hole(璐績+鏋氫婦)http://www.shnenglu.com/cxiaojia/archive/2012/05/06/173821.htmlC灝忓姞C灝忓姞Sun, 06 May 2012 06:50:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/05/06/173821.htmlhttp://www.shnenglu.com/cxiaojia/comments/173821.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/05/06/173821.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/173821.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/173821.html

寰堥仐鎲炬瘮璧涚殑鏃跺欐病鍋氬嚭鏉ワ紝褰撴椂鐢ㄨ椽蹇冪殑鏂規硶鍐欒繃錛屽彲鏄濊礬鏈夐棶棰橈紝WA浜嗐傝В棰樻姤鍛婁笂闈㈠彧璇存槸璐績錛屼絾鍏蜂綋鎬庝箞鍐欐病鏈夎銆備簬鏄垜灝卞皾璇曚簡涓浜涜椽蹇冩兂娉曪紝緇堜簬AC銆?4ms鐨勬椂闂磋繕鎸洪潬鍓嶇殑銆?/span>

 棰樻剰錛歂涓侀紶媧炲拰N涓侀紶錛岃侀紶鏈変釜鍏磋叮鍖洪棿[s,t]錛屽氨鏄鑰侀紶浼氬榪欎釜鑼冨洿鍐呯殑媧炴劅鍏磋叮錛屼粬浠細鍗犻鑷繁鎰熷叴瓚g殑媧炪傛湁涓涓叴瓚f嘗鍔ㄨ寖鍥碖錛屾眰涓涓渶灝忕殑K浣垮緱鎵鏈夌殑鑰侀紶閮借兘鍗犻鑷繁鎰熷叴瓚g殑媧炪?/p>

鍒嗘瀽錛氭寜鐓у乏杈瑰尯闂翠粠灝忓埌澶ф帓搴忥紝鐒跺悗寮濮嬫灇涓炬瘡涓涓尯闂達紝浠庡尯闂村彸杈圭殑绔偣寮濮嬫斁錛屽鏋滈偅涓綅緗凡緇忔湁鑰侀紶鐨勮瘽錛屽氨鍚戝墠閬嶅巻涓閬嶇湅鍓嶈竟鐨勬礊鏄惁宸叉弧錛屾病鏈夋弧鐨勮瘽灝卞悜鍓嶉亶鍘嗭紝閬囧埌宸︾鐐圭殑鍊煎皬浜庤繖涓侀紶鐨勫乏绔偣鍊兼椂錛屽氨浜ゆ崲錛岀洿鍒伴亣鍒頒竴涓┖媧炪傚鏋滄弧浜嗙殑璇濆氨鍚戝悗閬嶅巻錛岄亣鍒板彸绔偣澶т簬榪欎釜鑰侀紶鐨勫彸绔偣鏃訛紝灝變氦鎹紝鐩村埌閬囧埌涓涓┖媧炪傞亶鍘嗙殑鏃跺欒鏃跺埢鍒ゆ柇K鐨勫鹼紝濡傛灉鍒拌揪涓嶄簡閭d釜鑼冨洿錛屽氨澧炲ぇK鐨勫箋?br />

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef struct
{
    int s,t;
}ract;
ract r[503];
int line[503];
bool cmp(ract r1,ract r2)
{
    if(r1.s==r2.s) return r1.t<r2.t;
    return r1.s<r2.s;
}

int main()
{
    int t,pos=0;
    scanf("%d",&t);
    while(t--)
    {
        memset(line,-1,sizeof(line));
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;++i)
        {
            scanf("%d %d",&r[i].s,&r[i].t);
        }
        sort(r,r+n,cmp);
        int k=0;
        for(int i=0;i<n;++i)
        {
            if(line[r[i].t]==-1)//濡傛灉鍙崇鐐圭殑媧炴槸絀虹殑
            {
                line[r[i].t]=i;
            }
            else
            {
                int flag=0,temp=i;
                if(r[i].t>1)
                 for(int j=r[i].t-1;j>=1;--j)//鍚戝墠閬嶅巻錛屾槸鍚﹀凡浣忔弧
                 {
                     if(line[j]==-1) {flag=1;break;}
                 }
                 if(flag==1)
                for(int j=r[i].t;j>=1;--j)//濡傛灉娌℃湁浣忔弧灝卞悜鍓嶉亶鍘?/span>
                {
                    if(line[j]==-1)//閬囧埌絀烘礊灝變綇涓?/span>
                    {
                        line[j]=temp;
                        if(r[temp].s>j)
                        k=max(k,r[temp].s-j);//鏇存柊K鍊?/span>
                        break;
                    }
                    else if(r[line[j]].s<r[temp].s)//濡傛灉褰撳墠媧炰腑鐨勮侀紶鐨勫乏绔偣灝忎簬縐誨姩鐨勮侀紶鐨勫乏绔偣錛屽氨浜ゆ崲
                    {
                        int tmp2=line[j];
                        line[j]=temp;
                        if(r[temp].s>j)
                        k=max(k,r[temp].s-j);
                        temp=tmp2;
                    }
                }
                else
                {
                    for(int j=r[i].t;j<=n;++j)//濡傛灉宸茬粡浣忔弧灝卞悜鍚庨亶鍘?/span>
                    {
                        if(line[j]==-1)
                        {
                            line[j]=temp; 
                            if(r[temp].t<j)
                            k=max(k,j-r[temp].t);
                            break;
                        }
                        else
                        {
                            if(r[line[j]].t>r[temp].t)
                            {
                                int tmp2=line[j];
                                line[j]=temp;
                                if(r[temp].t<j)
                                 k=max(k,j-r[temp].t);
                                 temp=tmp2;
                            }
                            
                        }
                    }
                }
            }

        }
        printf("Case #%d: %d\n",++pos,k);

    }
    return 0;
}

 



C灝忓姞 2012-05-06 14:50 鍙戣〃璇勮
]]>
poj 3667 NYOJ 534 hotel 錛堝尯闂村悎騫剁嚎孌墊爲錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/05/04/173681.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Fri, 04 May 2012 12:05:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/05/04/173681.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/173681.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/05/04/173681.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/173681.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/173681.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">鍖洪棿鍚堝茍鐨勭嚎孌墊爲棰橈紝涔熸槸鎴戠殑絎竴涓尯闂村悎騫躲?/span></p> <p style="margin-top:0cm;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm; line-height:20.4pt;background:white;vertical-align:baseline">棰樻剰錛堣漿錛夛細<span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">Bessie</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">絳夌墰鍒板姞鎷垮ぇ鐨勬寰瘋礉鍘誨闀挎枃鍖栦慨鍏誨甯﹁璧忚嫃蹇呭埄灝旀箹鐨勯槼鍏夈傛寜鐓у娓哥殑浠嬬粛錛?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">Bessie</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">閫夋嫨浜嗚憲鍚嶇殑</span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">Cumberland</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">澶ц涓婄殑</span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">Bullmoose</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">瀹鵑浣滀負灞呬綇鐨勫湴鐐廣?/span></p> <p style="margin:0cm;margin-bottom:.0001pt;line-height:20.4pt;background:white; vertical-align:baseline"><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">榪欏駭宸ㄥ瀷瀹鵑鍦ㄤ竴鏉¤秴闀胯蛋寤婁笂鏈?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">N</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">錛?/span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">1 ≤ N ≤ 50000</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">錛変釜鎺掓垚涓鎺掔殑鎴塊棿錛屾瘡涓埧闂撮兘鑳芥璧忓埌鑻忓繀鍒╁皵婀栫殑濂芥櫙鑹層傜幇鍦ㄦ墍鏈夌殑鎴塊棿閮芥槸絀虹殑銆?/span></p> <p style="margin-top:0cm;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm; line-height:20.4pt;background:white;vertical-align:baseline"><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">鐜板湪</span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">Bessie</span><span style="font-size: 11.5pt; ">絳夋梾瀹滑姝e湪涓嶆柇鍦板彂鍑鴻鎴垮拰閫鎴胯姹傘備綘闇瑕佹帴鍙?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">M</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">錛?/span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">1 ≤ M < 50000</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">錛夋潯鎸囦護錛?/span></p> <p style="margin-top:0cm;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm; line-height:20.4pt;background:white;vertical-align:baseline"><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">姣忔潯鎸囦護鐨勭涓涓暟瀛椾負</span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">1</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">鎴?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">2</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">銆傚鏋滄槸</span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">1</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">錛屽悗闈㈠皢鏈変竴涓暣鏁?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">D</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">琛ㄧず欏懼瑕侀瀹氱殑鎴塊棿鏁般傛敞鎰忥紝榪欎簺鎴塊棿蹇呴』鏄繛緇殑銆傚鏋滆兘澶熸弧瓚蟲梾瀹㈢殑璁㈡埧瑕佹眰錛岃緭鍑烘弧瓚寵姹傜殑絎竴涓埧闂寸殑緙栧彿錛堜緥濡傦紝瑕佽鎴?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">6</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">闂達紝杈撳嚭</span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">3</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">琛ㄧず</span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">3, 4, 5, 6, 7, 8</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">鏄弧瓚寵姹傜殑錛夛紝榪欐牱鐨勭紪鍙峰繀欏繪槸鍙兘鐨勭紪鍙烽噷闈㈡渶闈犲墠鐨勩傚鏋滀笉鑳芥弧瓚寵姹傦紝杈撳嚭</span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">0</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">銆?/span></p> <p style="margin-top:0cm;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm; line-height:20.4pt;background:white;vertical-align:baseline"><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">濡傛灉鏄?/span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">2</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">錛屽悗闈㈠皢鏈変袱涓暣鏁?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">X</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">鍜?/span><span style="font-size:11.5pt;font-family:"Segoe UI","sans-serif"; color:#333333">D</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">琛ㄧず欏懼瑕侀鎺?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">X, X + 1, X + 2, ... , X + D - 1</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI";color:#333333">榪?/span><span style="font-size:11.5pt; font-family:"Segoe UI","sans-serif";color:#333333">D</span><span style="font-size:11.5pt;Segoe UI";Segoe UI";Segoe UI"; color:#333333">闂存埧銆傚浜庤繖鏍風殑鎸囦護浠涔堥兘涓嶈緭鍑恒?/span></p> <p><span style="font-family:瀹嬩綋;">鍒嗘瀽錛?/span></p> <p><span style="font-family:瀹嬩綋;">鍒嗗埆鐢?/span>lsum<span style="font-family:瀹嬩綋;">錛?/span>rsum<span style="font-family:瀹嬩綋;">鍜?/span>msum<span style="font-family:瀹嬩綋;">琛ㄧず鍖洪棿宸﹁竟鏈澶ц繛緇埧闂存暟錛屽尯闂村彸杈規渶澶ц繛緇埧闂存暟鍜屽尯闂存渶澶ц繛緇埧闂存暟銆?/span></p> <p><span style="font-family:瀹嬩綋;">鏌ヨ鐨勬椂鍊欙紝鍏堟壘宸﹀効瀛愭槸鍚﹁凍澶燂紝鐒跺悗濡傛灉涓嶅灝辨壘宸﹀効瀛愮殑鍙沖尯闂村拰鍙沖効瀛愮殑宸﹀尯闂寸殑鍜屾槸鍚﹁凍澶燂紝濡傛灉涓や釜閮戒笉澶熺殑璇濆氨鎵懼彸鍎垮瓙錛堣繖涓椂鍊欏彸鍎垮瓙灝辮偗瀹氭弧瓚充簡錛夈?/span></p> <p><span style="font-family:瀹嬩綋;">鏌ヨ緇撴潫鏃惰鎶婅繖涓尯闂寸殑鎴垮瓙鏇存柊鎴愬凡浣忋?/span></p> <p><span style="font-family:瀹嬩綋;">鏇存柊鐨勬椂鍊欏拰鏅氱殑綰挎鏍戣妭鐐規洿鏂版槸涓鏍風殑錛屼笉鍚岀殑鏄湪鏇存柊瀹屽瓙鑺傜偣鍚庯紝瑕佹妸瀛愯妭鐐圭殑淇℃伅鍙嶉鍒扮埗鑺傜偣涓?/span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">鍦?/span>NYOJ<span style="font-family:瀹嬩綋;">涓彁浜?/span>TLE<span style="font-family:瀹嬩綋;">錛屽師鍥犲眳鐒舵槸瀹忓畾涔夋瘮</span>inline<span style="font-family:瀹嬩綋;">蹇?br /><br /></span><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstring><br />#include<cctype><br />#include<cstdio><br />#include<algorithm><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">娌℃兂鍒版垜鎶奿nline鎹㈡垚瀹忓畾涔夊悗灝盇C浜嗭紝鐞嗚涓婅繖涓や釜涓鏍風殑錛屼絾鏄痠nline鐨勭粨鏋滃嵈鏄疶LE</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">#define</span> L(r) r<<1<br /><span style="color: #0000FF; ">#define</span> R(r) r<<1|1<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">inline int MID(int l,int r){return (l+r)>>1;}<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">inline int L(int r){return r<<1;}<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">inline int R(int r){return r<<1|1;}</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> MAXM=50005;<br />typedef <span style="color: #0000FF; ">struct</span><br />{<br />    <span style="color: #0000FF; ">int</span> lsum,rsum,msum;<span style="color: #008000; ">//</span><span style="color: #008000; ">鍒嗗埆琛ㄧず宸﹁竟鏈澶ф埧闂存暟錛屽彸杈規渶澶ф埧闂存暟錛屾暣浣撴渶澶ф埧闂存暟</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">int</span> cover;<span style="color: #008000; ">//</span><span style="color: #008000; ">鏄惁浣忎笅</span><span style="color: #008000; "><br /></span>}node;<br />node tree[MAXM<<2];<br /><span style="color: #0000FF; ">void</span> pushDown(<span style="color: #0000FF; ">int</span> root,<span style="color: #0000FF; ">int</span> m)<span style="color: #008000; ">//</span><span style="color: #008000; ">鍚戜笅鏇存柊</span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(tree[root].cover==-1) <span style="color: #0000FF; ">return</span>;<span style="color: #008000; ">//</span><span style="color: #008000; ">鏄惁宸茬粡鏇存柊</span><span style="color: #008000; "><br /></span>    tree[L(root)].cover=tree[R(root)].cover=tree[root].cover;<br />    tree[L(root)].msum=tree[L(root)].lsum=tree[L(root)].rsum=tree[root].cover?0:m-(m>>1);<br />    tree[R(root)].msum=tree[R(root)].lsum=tree[R(root)].rsum=tree[root].cover?0:(m>>1);<br />    tree[root].cover=-1;<br />}<br /><span style="color: #0000FF; ">void</span> pushUp(<span style="color: #0000FF; ">int</span> root,<span style="color: #0000FF; ">int</span> m)<span style="color: #008000; ">//</span><span style="color: #008000; ">鍚戜笂鏇存柊</span><span style="color: #008000; "><br /></span>{<br />    tree[root].lsum=tree[L(root)].lsum;<br />    tree[root].rsum=tree[R(root)].rsum;<br />    <span style="color: #0000FF; ">if</span>(tree[root].lsum==m-(m>>1) ) tree[root].lsum+=tree[R(root)].lsum;<br />    <span style="color: #0000FF; ">if</span>(tree[root].rsum==(m>>1) ) tree[root].rsum+=tree[L(root)].rsum;<br />    tree[root].msum=max(tree[R(root)].lsum+tree[L(root)].rsum,max(tree[L(root)].msum,tree[R(root)].msum) );<br />}<br /><span style="color: #0000FF; ">void</span> Create(<span style="color: #0000FF; ">int</span> l,<span style="color: #0000FF; ">int</span> r,<span style="color: #0000FF; ">int</span> root)<span style="color: #008000; ">//</span><span style="color: #008000; ">寤烘爲榪囩▼</span><span style="color: #008000; "><br /></span>{<br />    tree[root].cover=-1;<br />    tree[root].lsum=tree[root].rsum=tree[root].msum=r-l+1;<br />    <span style="color: #0000FF; ">if</span>(l==r){<span style="color: #0000FF; ">return</span>;}<br />    <span style="color: #0000FF; ">int</span> mid=(l+r)>>1;<br />    Create(l,mid,L(root));<br />    Create(mid+1,r,R(root));<br />}<br /><span style="color: #0000FF; ">void</span> update(<span style="color: #0000FF; ">int</span> ll,<span style="color: #0000FF; ">int</span> rr,<span style="color: #0000FF; ">int</span> c,<span style="color: #0000FF; ">int</span> l,<span style="color: #0000FF; ">int</span> r,<span style="color: #0000FF; ">int</span> root)<span style="color: #008000; ">//</span><span style="color: #008000; ">鏇存柊</span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(ll<=l&&r<=rr)<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉鎵懼埌榪欎釜鑼冨洿灝辯洿鎺ヨ祴鍊艱繑鍥烇紝涓嶅悜涓嬬戶緇洿鏂?/span><span style="color: #008000; "><br /></span>    {<br />        tree[root].msum=tree[root].lsum=tree[root].rsum=c?0:r-l+1;<br />        tree[root].cover=c;<br />        <span style="color: #0000FF; ">return</span>;<br />    }<br />    pushDown(root,r-l+1);<span style="color: #008000; ">//</span><span style="color: #008000; ">鐢ㄥ埌榪欎釜鑺傜偣鐨勫瓙鑺傜偣鐨勬椂鍊欏氨鍚戜笅鏇存柊</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">int</span> m=(l+r)>>1;<br />    <span style="color: #0000FF; ">if</span>(ll<=m) update(ll,rr,c,l,m,L(root));<br />    <span style="color: #0000FF; ">if</span>(m<rr) update(ll,rr,c,m+1,r,R(root));<br />    pushUp(root,r-l+1);<span style="color: #008000; ">//</span><span style="color: #008000; ">鍚戜笅鏇存柊瀹屽悗闇瑕佹妸鑺傜偣淇℃伅鍙嶉緇欑埗鑺傜偣</span><span style="color: #008000; "><br /></span>}<br /><span style="color: #0000FF; ">int</span> query(<span style="color: #0000FF; ">int</span> w,<span style="color: #0000FF; ">int</span> l,<span style="color: #0000FF; ">int</span> r,<span style="color: #0000FF; ">int</span> root)<span style="color: #008000; ">//</span><span style="color: #008000; ">鏌ヨ婊¤凍榪炵畫鎴塊棿鏁伴噺鐨勬渶宸﹁妭鐐?/span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(l==r) <span style="color: #0000FF; ">return</span> l;<br />    pushDown(root,r-l+1 );<span style="color: #008000; ">//</span><span style="color: #008000; ">鐢ㄥ埌榪欎釜鑺傜偣鐨勫瓙鑺傜偣鐨勬椂鍊欏氨鍚戜笅鏇存柊</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">int</span> m=(l+r)>>1;<br />    <span style="color: #0000FF; ">if</span>(tree[L(root)].msum>=w) <span style="color: #0000FF; ">return</span> query(w,l,m,L(root));<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉宸﹀効瀛愭弧瓚沖氨璇㈤棶宸﹀効瀛?/span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(tree[L(root)].rsum+tree[R(root)].lsum>=w) <span style="color: #0000FF; ">return</span> m-tree[L(root)].rsum+1;<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉宸﹀効瀛愬拰鍙沖効瀛愪箣闂寸殑鏁伴噺婊¤凍錛屽垯鑼冨洿宸﹀効瀛愬彸杈硅繛緇埧闂寸涓涓殑緙栧彿</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">return</span> query(w,m+1,r,R(root));<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉涓よ呴兘涓嶆弧瓚沖垯璇㈤棶鍙沖効瀛?/span><span style="color: #008000; "><br /></span>}<br /><br /><br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #008000; ">//</span><span style="color: #008000; ">freopen("in.txt","r",stdin);<br />    </span><span style="color: #008000; ">//</span><span style="color: #008000; ">freopen("out.txt","w",stdout);</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">int</span> n,m;<br />    <span style="color: #0000FF; ">while</span>(~scanf("%d %d",&n,&m))<br />    {<br />        Create(1,n,1);<br />        <span style="color: #0000FF; ">int</span> a,num,x,d,p;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<m;++i)<br />        {<br />            scanf("%d",&a);<br />            <span style="color: #0000FF; ">if</span>(1==a)<br />            {<br />                scanf("%d",&num);<br />                <span style="color: #0000FF; ">if</span>(tree[1].msum<num) puts("0");<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉鏁翠釜鍖洪棿鐨勬渶澶ц繛緇埧闂存暟閲忓皬浜庨瀹氱殑鏁伴噺灝辮緭鍑?</span><span style="color: #008000; "><br /></span>                <span style="color: #0000FF; ">else</span><br />                {<br />                    p=query(num,1,n,1);<span style="color: #008000; ">//</span><span style="color: #008000; ">鎵懼埌鏈宸﹁妭鐐筽</span><span style="color: #008000; "><br /></span>                    printf("%d\n",p);<br />                    update(p,p+num-1,1,1,n,1);<span style="color: #008000; ">//</span><span style="color: #008000; ">鎶婂凡緇忔湁浜虹殑鎴塊棿鏍囪涓涓?/span><span style="color: #008000; "><br /></span>                }<br /><br />            }<br />            <span style="color: #0000FF; ">else</span><br />            {<br />                scanf("%d %d",&x,&d);<br />                update(x,x+d-1,0,1,n,1);<span style="color: #008000; ">//</span><span style="color: #008000; ">鎶婃鑼冨洿鐨勬埧闂存爣璁版垚鏃犱漢</span><span style="color: #008000; "><br /></span><br />            }<br />        }<br />    }<br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/173681.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-05-04 20:05 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/05/04/173681.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>NYOJ 290 鍔ㄧ墿緇熻鍔犲己鐗堬紙瀛楀吀鏍戝濮楁潵榪燂級http://www.shnenglu.com/cxiaojia/archive/2012/05/03/173583.htmlC灝忓姞C灝忓姞Thu, 03 May 2012 08:17:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/05/03/173583.htmlhttp://www.shnenglu.com/cxiaojia/comments/173583.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/05/03/173583.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/173583.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/173583.html瀛楀吀鏍戞槸涓縐嶆爲褰㈢殑鏁版嵁緇撴瀯錛屾彃鍏ョ殑澶嶆潅搴︿負鍗曡瘝鐨勫鉤鍧囬暱搴︺傛湰棰樺彧闇瑕佸啓涓涓彃鍏ュ嚱鏁板氨鍙互浜嗐?br />鐢變簬榪囧嚑澶╁氨瑕佺渷璧涗簡錛岀瓑鍒扮渷璧涘悗鎬葷粨涓涓嬪瓧鍏告爲銆?br />
// trietree.cpp : 瀹氫箟鎺у埗鍙板簲鐢ㄧ▼搴忕殑鍏ュ彛鐐廣?br />//
#include<cstdio>
#include<iostream>
#include<string.h>

using namespace std;
const int num_chars = 26;            //鍏抽敭鐮佹渶澶т綅

int _max;
char ans[12];

class Trie
{
public:
    Trie();
    Trie(Trie& tr);
    virtual ~Trie();
    //int trie_search(const char* word, char*entry) const;
    bool insert(const char* word);
protected:
    struct Trie_node   //鍏抽敭鐮佺被鍨?/span>
    {
        bool isfin;
        int cnt;                     //鍏抽敭鐮佸綋鍓嶄綅鏁?/span>
        Trie_node* branch[num_chars];   //鍏抽敭鐮佸瓨鏀炬暟緇?/span>
        Trie_node();
    };
    Trie_node* root;
};

Trie::Trie_node::Trie_node()   //緇撶偣瀹氫箟
{
    isfin = false;
    cnt = 0;
    for(int i = 0; i < num_chars;++i)
        branch[i] = NULL;
}

Trie::Trie():root(NULL)
{
}

Trie::~Trie()
{
}



bool Trie::insert(const char*word)
{
    int result = 1,position = 0;
    if(root == NULL)
        root = new Trie_node;
    char char_code;
    Trie_node *location = root;
    while(location != NULL && *word != 0)
    {
        if(*word >= 'a'&& *word <= 'z')
            char_code = *word - 'a';
        if(location->branch[char_code] == NULL)
            location->branch[char_code] = new Trie_node;
        location = location->branch[char_code];
        position++;
        word++;
    }

    ++location->cnt;
    if(location->cnt>_max)
    {
        _max=location->cnt;
        return true;
    }
    else
    return false;
}


int main()
{
    Trie t;
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        _max=0;
        char s[12];
        for(int i=0;i<n;++i)
        {
            scanf("%s",s);
            if(t.insert(s))
            {
                strcpy(ans,s);
            }

        }
        printf("%s %d\n",ans,_max);
    }


    return 0;
}


C灝忓姞 2012-05-03 16:17 鍙戣〃璇勮
]]>
poj 1159 Palindrome NYOJ 37 鍥炴枃瀛楃涓?DP)http://www.shnenglu.com/cxiaojia/archive/2012/04/10/170810.htmlC灝忓姞C灝忓姞Tue, 10 Apr 2012 13:01:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/04/10/170810.htmlhttp://www.shnenglu.com/cxiaojia/comments/170810.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/04/10/170810.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/170810.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/170810.html

榪欓亾棰樻湁涓ょ瑙f硶錛?/span>

絎竴縐嶏細姹?/span>s鍜?/span>~s鐨?/span>LCS錛岀劧鍚庡鐢ㄥ叕寮?/span>length-LCS闀垮害 鍗充負鎵姹傘?/span>

絎簩縐嶏細鐩存帴DP姹傝В銆?/span>

褰?/span>s[i] == s[j]鏃?/span>  f[i][j]=f[i+1][j-1]

  褰?/span>s[i] != s[j]鏃?/span>  f[i][j]=min(f[i+1][j],f[i][j-1])+1;

 

榪欎釜棰樻垜鐢ㄧ殑鏄竴涓ぇ鍨嬬殑浜岀淮鏁扮粍錛屼唬鐮佸緢姘達紝涓嶅緩璁璧忋?/span>

 

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXM=1001;
short int  f[MAXM][MAXM];
char s[1001];
int LCS()
{

    scanf("%s",s);
    memset(f,0,sizeof(f));
    int len=strlen(s);
    for(int i=0;i<len;++i)
    {
        for(int j=i;j>=0;--j)
        {
            if(s[i]==s[j])
            {
                f[i+1][j+1]=f[i][j+2];
            }
            else
            {
                f[i+1][j+1]=min(f[i][j+1],f[i+1][j+2])+1;
            }
        }
    }
    return f[len][1];
}

int main()
{
    int n;

    cin>>n;
    while(n--)
    {
        printf("%d\n",LCS());
    }


    return 0;
}
                



C灝忓姞 2012-04-10 21:01 鍙戣〃璇勮
]]>
poj 1157 LITTLE SHOP OF FLOWERS錛堢畝鍗旸P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/04/10/170755.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Tue, 10 Apr 2012 03:23:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/04/10/170755.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/170755.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/04/10/170755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/170755.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/170755.html</trackback:ping><description><![CDATA[<div><p style="line-height:19.5pt;background:white"><span style="font-size:10.5pt;color:#333333">棰樻剰</span><span style="font-size:10.5pt; font-family:"Arial","sans-serif";color:#333333">(</span><span style="font-size: 10.5pt;color:#333333">杞?/span><span style="font-size:10.5pt; font-family:"Arial","sans-serif";color:#333333">)</span><span style="font-size: 10.5pt;color:#333333">錛氬皢鏌愪簺鑺辨斁鍏ユ煇浜涜姳鐡朵腑寰楀埌鐨勮璧忎環鍊兼槸涓嶅悓鐨勶紝騫朵笖瑕佹眰寮濮嬭緭鍏ョ殑鏁版嵁蹇呴』鍦ㄥ悗杈撳叆鐨勬暟鎹墠闈€傚嵆</span><span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:#333333">:</span><span style="font-size:10.5pt;color:#333333">鑻ヤ竴鍙瘋姳鏀懼叆浜?/span><span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:#333333">3</span><span style="font-size:10.5pt;color:#333333">鍙瘋姳鐡訛紝閭d箞鍚庨潰鐨勮姳灝變笉鑳芥斁鍏?/span><span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:#333333">1</span><span style="font-size:10.5pt;color:#333333">錛?/span><span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:#333333">2</span><span style="font-size:10.5pt;color:#333333">鍙瘋姳鐡朵簡銆?/span></p> <p><span style="font-family:瀹嬩綋;">鍒嗘瀽錛氱畝鍗?/span>DP<span style="font-family:瀹嬩綋;">銆?/span>Dp[i][j]<span style="font-family:瀹嬩綋;">琛ㄧず鍓?/span>i<span style="font-family:瀹嬩綋;">鏈佃姳鎸夐『搴忔斁鍏ュ墠</span>j <span style="font-family:瀹嬩綋;">涓姳鐡朵腑鐨勬渶浼樿璧忎環鍊箋?/span></p> <p><span style="font-family:瀹嬩綋;">鐘舵佽漿縐繪柟紼嬶細</span>dp[i][j]=max(dp[i][j-1],dp[i-1][j-1]+map[i][j])</p> <p><span style="font-family:瀹嬩綋;">鍓?/span>i<span style="font-family:瀹嬩綋;">鏈佃姳鎸夐『搴忔斁鍏ュ墠</span>j <span style="font-family:瀹嬩綋;">涓姳鐡朵腑鐨勬渶浼樿璧忎環鍊?/span>=max<span style="font-family:瀹嬩綋;">錛堝墠</span>i<span style="font-family:瀹嬩綋;">鏈佃姳鎸夐『搴忔斁鍏ュ墠</span>j -1<span style="font-family:瀹嬩綋;">涓姳鐡朵腑鐨勬渶浼樿璧忎環鍊鹼紝鍓?/span>i-1<span style="font-family:瀹嬩綋;">鏈佃姳鎸夐『搴忔斁鍏ュ墠</span>j -1<span style="font-family:瀹嬩綋;">涓姳鐡朵腑鐨勬渶浼樿璧忎環鍊?/span>+<span style="font-family:瀹嬩綋;">絎?/span>i<span style="font-family:瀹嬩綋;">鏈佃姳鏀懼叆</span>j<span style="font-family:瀹嬩綋;">鐡朵腑鐨勪環鍊鹼級</span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">娉ㄦ剰浠峰煎彲鑳戒負璐熸暟銆?br /><br /></span><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstdio><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> INF=0x7fffffff-1;<br /><span style="color: #0000FF; ">int</span> map[103][103];<br /><span style="color: #0000FF; ">int</span> dp[103][103];<br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #0000FF; ">int</span> f,v;<br />    scanf("%d %d",&f,&v);<br /><br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=f;++i)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<=v;++j)<br />            {<br />                scanf("%d",&map[i][j]);<br />            }<br />        }<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<=f;++i)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<=v;++j)<br />            {<br />                dp[i][j]=-INF;<br />            }<br />        }<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<=v;++j)<br />        {<br />            <span style="color: #0000FF; ">int</span> zc=min(j,f);<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=zc;++i)<br />            {<br />                <span style="color: #0000FF; ">int</span> temp=dp[i-1][j-1]==-INF?0:dp[i-1][j-1];<br />                dp[i][j]=max(dp[i][j-1],temp+map[i][j]);<br />            }<br />        }<br />        printf("%d\n",dp[f][v]);<br /><br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/170755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-04-10 11:23 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/04/10/170755.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 1042 Gone Fishing錛堣椽蹇?鏋氫婦錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/04/06/170232.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Fri, 06 Apr 2012 00:13:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/04/06/170232.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/170232.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/04/06/170232.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/170232.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/170232.html</trackback:ping><description><![CDATA[<div><p><a name="OLE_LINK2" style="width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=image&file=anchor.gif); background-repeat: no-repeat no-repeat; "></a><span style="font-family:瀹嬩綋;">絎竴嬈?/span>WA<span style="font-family:瀹嬩綋;">錛屽彂鐜拌緭鍑烘牸寮忎笉瀵癸紝鏀規帀銆?/span></p> <p><span style="font-family:瀹嬩綋;">絎簩嬈?/span>WA<span style="font-family:瀹嬩綋;">錛屽緇撴灉鐩哥瓑鐨勬儏鍐墊病鏈夎冭檻錛屾敼鎺夈?/span></p> <p><span style="font-family:瀹嬩綋;">絎笁嬈?/span>AC<span style="font-family:瀹嬩綋;">銆?/span></p> <p><span style="font-family:瀹嬩綋;">棰樻剰鍜岄瑙h榛戜功</span>P13<span style="font-family:瀹嬩綋;">銆?/span></p> <p><span style="font-family:瀹嬩綋;">闇瑕佹敞鎰忕殑鏄鏋氫婦浠庣涓涓箹璧板埌鏈鍚庝竴涓箹鐨勬瘡涓縐嶆儏鍐碉紝瀵圭粨鏋滅浉絳夎繖縐嶆儏鍐靛仛鐗規畩澶勭悊銆?br /><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstdio><br />#include<cstring><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> MAXM=30;<br /><span style="color: #0000FF; ">int</span> n,h;<br /><span style="color: #0000FF; ">int</span> f[MAXM],d[MAXM],t[MAXM];<br /><span style="color: #0000FF; ">int</span> each_time[MAXM];<br /><span style="color: #0000FF; ">int</span> ans_time[MAXM];<br /><span style="color: #0000FF; ">int</span> tf[MAXM];<br /><span style="color: #0000FF; ">int</span> ans;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">鍒濆鍖?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> init()<br />{<br />    memset(each_time,0,<span style="color: #0000FF; ">sizeof</span>(each_time));<br />    memset(ans_time,0,<span style="color: #0000FF; ">sizeof</span>(ans_time));<br />    ans=0;<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">杈撳叆</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">bool</span> input()<br />{<br />    init();<br />    scanf("%d",&n);<br />    <span style="color: #0000FF; ">if</span>(0==n) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />    scanf("%d",&h);<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;++i)<br />    {<br />        scanf("%d",f+i);<br />    }<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;++i)<br />    {<br />        scanf("%d",d+i);<br />    }<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n-1;++i)<br />    {<br />        scanf("%d",t+i);<br />    }<br />    <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />}<br /><br /><span style="color: #0000FF; ">void</span> solve(<span style="color: #0000FF; ">int</span> rem_time,<span style="color: #0000FF; ">int</span> q)<br />{<br />    <span style="color: #0000FF; ">int</span> tans=0;<br />    memset(each_time,0,<span style="color: #0000FF; ">sizeof</span>(each_time));<br /><br />    memcpy(tf,f,<span style="color: #0000FF; ">sizeof</span>(f));<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<rem_time;++i)<span style="color: #008000; ">//</span><span style="color: #008000; ">鎵鵑奔鐨勬暟閲忔渶澶氱殑婀?/span><span style="color: #008000; "><br /></span>        {<br />            <span style="color: #0000FF; ">int</span> pos=0,max_fish=tf[0];<br />            <span style="color: #0000FF; ">if</span>(q>0)<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<=q;++j)<br />            {<br />                <span style="color: #0000FF; ">if</span>(max_fish<tf[j])<br />                {<br />                    max_fish=tf[j];<br />                    pos=j;<br />                }<br />            }<br />            ++each_time[pos];<br />            tans+=tf[pos];<br />            tf[pos]-=d[pos];<br />            <span style="color: #0000FF; ">if</span>(tf[pos]<0) tf[pos]=0;<br /><br />        }<br />        <span style="color: #0000FF; ">if</span>(tans>ans)<br />        {<br />            ans=tans;<br />            memcpy(ans_time,each_time,<span style="color: #0000FF; ">sizeof</span>(each_time));<br />        }<br />        <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span>(tans==ans)<span style="color: #008000; ">//</span><span style="color: #008000; ">緇嗚妭錛岀瓟妗堢浉絳夋椂鍋氱殑澶勭悊銆?/span><span style="color: #008000; "><br /></span>        {<br />            <span style="color: #0000FF; ">int</span> i;<br />            <span style="color: #0000FF; ">for</span>(i=0;i<n;++i)<br />            {<br />                <span style="color: #0000FF; ">if</span>(each_time[i]!=ans_time[i]) <span style="color: #0000FF; ">break</span>;<br />            }<br />            <span style="color: #0000FF; ">if</span>(each_time[i]>ans_time[i])<br />            {<br />                memcpy(ans_time,each_time,<span style="color: #0000FF; ">sizeof</span>(each_time));<br />            }<br />        }<br />}<br /><br /><span style="color: #0000FF; ">void</span> print()<br />{<br />    printf("%d",ans_time[0]*5);<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<n;i++)<br />    {<br />        printf(", %d",ans_time[i]*5);<br />    }<br />    printf("\nNumber of fish expected: %d\n\n",ans);<br />}<br /><span style="color: #0000FF; ">int</span> main()<br />{<br />   <span style="color: #008000; ">//</span><span style="color: #008000; "> freopen("in.txt","r",stdin);<br />   </span><span style="color: #008000; ">//</span><span style="color: #008000; "> freopen("out2.txt","w",stdout);</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">while</span>(input())<br />    {<br />        <span style="color: #0000FF; ">int</span> rem_time=h*60;<br />        rem_time/=5;<br />        solve(rem_time,0);<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n-1;++i)<span style="color: #008000; ">//</span><span style="color: #008000; ">鏋氫婦姣忎釜婀?/span><span style="color: #008000; "><br /></span>        {<br />            rem_time-=t[i];<br />            solve(rem_time,i+1);<br />        }<br />        print();<br /><br />    }<br /><br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/170232.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-04-06 08:13 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/04/06/170232.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 1036 Gangsters (DP)http://www.shnenglu.com/cxiaojia/archive/2012/03/29/169388.htmlC灝忓姞C灝忓姞Thu, 29 Mar 2012 03:37:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/29/169388.htmlhttp://www.shnenglu.com/cxiaojia/comments/169388.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/29/169388.html#Feedback1http://www.shnenglu.com/cxiaojia/comments/commentRss/169388.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/169388.html

棰樻剰錛氬棣嗘湁涓彲浠ヤ幾緙╃殑闂紝姣忕閽熷彲浠ヤ幾闀?/span>1涓崟浣嶏紝鎴栬呯緝灝?/span>1涓崟浣嶏紝鎴栬呭師鍦頒笉鍔ㄣ傛湁N涓己鐩楋紝姣忎釜寮虹洍浼氬湪t鐨勬椂闂村唴鍒拌揪騫舵寜錛屽鏋滄鏃墮棬鐨勫紑鏂瑰害鍜屼粬鐨勮韓鏉?/span>s姝eソ鐩哥瓑錛岃繖涓己鐩楀氨浼氳繘鏉ワ紝鐒跺悗浣犲氨鑳藉緱鍒?/span>p鐨勫姞鍒嗐?/span>

鍒濆鐘舵侀棬鏄叧闂殑錛岃浣犳眰鍑哄湪t鏃跺埢寰楀埌鐨勬渶澶у緱鍒嗐?/span>

 

鍒嗘瀽錛氭寜鏃墮棿浠庡皬鍒板ぇ鎺掑簭錛?/span>t鏃墮棿鍐呮渶澶х殑寰楀垎鐢?/span>t涔嬪墠鐨勬椂鍒誨喅瀹氾紝婊¤凍鏃犲悗鏁堟э紝姣忎竴涓椂鍒婚兘鑳藉緱鍒版渶浼樿В錛屾弧瓚蟲渶鏈夊瓙緇撴瀯錛屾墍浠?/span>DP銆?/span>

F[i]琛ㄧず絎?/span>i涓漢銆?/span>

褰撹韓鏉愪箣宸皬浜庢椂闂翠箣宸椂F[i]=max(f[i],f[j]+ple[i].p) 0<=j<i 浣嗗緱婊¤凍涓涓潯浠訛紝絎?/span>j涓漢宸茬粡榪涘幓錛屽惁鍒欓棬浼擱暱鐨勫搴﹀彲鑳戒細灝忎簬韜潗銆?br />

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXM=103;

typedef struct People
{
    int t,p,s;

}People;
People ple[MAXM];
int f[MAXM];
bool cmp(People p1,People p2)
{
    return p1.t<p2.t;
}
int main()
{
    int n,k,s;
    scanf("%d %d %d",&n,&k,&s);
    for(int i=1;i<=n;++i)
        scanf("%d",&ple[i].t);
    for(int i=1;i<=n;++i)
        scanf("%d",&ple[i].p);
    for(int i=1;i<=n;++i)
        scanf("%d",&ple[i].s);
    sort(ple+1,ple+n+1,cmp);
    f[0]=0;
    ple[0].p=0;ple[0].s=0;ple[0].t=0;
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=i-1;j>=0;--j)
        {
            if(f[j]>=ple[j].p)//涓嬩竴姝ュ仛宸殑鍩虹鏄j涓漢宸茬粡榪涘幓銆?/span>
                if(abs(ple[i].s-ple[j].s)<=ple[i].t-ple[j].t)
                    f[i]=max(f[i],f[j]+ple[i].p);
        }
        ans=max(ans,f[i]);
    }
    printf("%d\n",ans);

    return 0;
}



C灝忓姞 2012-03-29 11:37 鍙戣〃璇勮
]]>
foj 2077 The tallest tree 錛堝急鐖嗕簡錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/27/169100.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Tue, 27 Mar 2012 01:24:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/27/169100.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/169100.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/27/169100.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/169100.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/169100.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">鐪嬩簡瑙i鎶ュ憡涔嬪悗鎴戝湪鎯籌紝涓轟粈涔堟垜浼氬偦鍌葷殑鍘繪妸姣忎竴澶╃殑楂樺害閮芥眰鍑烘潵銆傘傘傘?/span></p> <p> </p> <p><span style="font-family: 瀹嬩綋; ">璇㈤棶鍝竴澶╁氨姹傚嚭鍝竴澶╃殑楂樺害錛屾妸澶╂暟鎺掍竴涓嬪簭鍙互鍦ㄦ眰鐨勮繃紼嬩腑鍒犳帀楂樺害鍜屽闀塊熷害閮藉皬鐨勬爲銆傛椂闂村鏉傚害</span><=O(m*n)<span style="font-family:瀹嬩綋;">銆?br /><br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstdio><br />#include<cstring><br />#include<algorithm><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br />typedef <span style="color: #0000FF; ">long</span> <span style="color: #0000FF; ">long</span> ll;<br /><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> MAXM=100003;<br />typedef <span style="color: #0000FF; ">struct</span><br />{<br />    ll high,add;<span style="color: #008000; ">//</span><span style="color: #008000; ">楂樺害鍜屽闀塊熷害</span><span style="color: #008000; "><br /></span>}Tree;<br />Tree tree[MAXM];<br />ll day[MAXM];<span style="color: #008000; ">//</span><span style="color: #008000; ">瀹為檯鐨勬暟澶?/span><span style="color: #008000; "><br /></span>ll sday[MAXM];<span style="color: #008000; ">//</span><span style="color: #008000; ">鎺掑簭鍚庣殑澶╂暟</span><span style="color: #008000; "><br /></span>ll ans[MAXM];<span style="color: #008000; ">//</span><span style="color: #008000; ">緇撴灉</span><br /><font color="#0000ff"><br /></font><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #0000FF; ">int</span> n,m;<br />    <span style="color: #0000FF; ">while</span>(scanf("%d %d",&n,&m)!=EOF)<br />    {<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;++i)<br />        {<br />            scanf("%lld %lld",&tree[i].high,&tree[i].add);<br />        }<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<m;++i)<br />        {<br />            scanf("%lld",day+i);<br />            sday[i]=day[i];<br />        }<br />        sort(sday,sday+m);<span style="color: #008000; ">//</span><span style="color: #008000; ">澶╂暟浠庡皬鍒板ぇ鎺掑簭</span><span style="color: #008000; "><br /></span>        memset(ans,0,<span style="color: #0000FF; ">sizeof</span>(ans));<br />        Tree tmax;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<m;++i)<span style="color: #008000; ">//</span><span style="color: #008000; ">鏋氫婦鎺掑簭鍚庣殑澶╂暟</span><span style="color: #008000; "><br /></span>        {<br />            tmax.high=tree[0].high+sday[i]*tree[0].add;<br />            tmax.add=tree[0].add;<br />            <span style="color: #0000FF; ">int</span> pos=1;<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<n;++j)<span style="color: #008000; ">//</span><span style="color: #008000; ">鏋氫婦姣忎竴棰楁爲</span><span style="color: #008000; "><br /></span>            {<br />                Tree temp=tree[j];<br />                temp.high+=sday[i]*tree[j].add;<br />                <span style="color: #0000FF; ">if</span>( !(tmax.high>=temp.high&&tmax.add>=temp.add) )<span style="color: #008000; ">//</span><span style="color: #008000; ">濡傛灉絎琷媯墊爲鍦╯day[i]鐨勯珮搴﹀拰澧為暱閫熷害閮藉皬浜庢煇媯墊爲錛屽垯鑸嶅純絎琷媯墊爲</span><span style="color: #008000; "><br /></span>                {<br />                    tree[pos++]=tree[j];<br />                }<br />                <span style="color: #008000; ">//</span><span style="color: #008000; ">鎵懼埌鍦╯day[i]鏃跺埢楂樺害鏈澶х殑鏍?/span><span style="color: #008000; "><br /></span>                <span style="color: #0000FF; ">if</span>(tmax.high<temp.high)<br />                {<br />                    tmax=temp;<br />                }<br />            }<br />            n=pos;<br />            ans[ sday[i] ]=tmax.high;<br />        }<br /><br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<m;++i)<br />            printf("%lld\n",ans[ day[i] ]);<br /><br />    }<br /><br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div><p> </p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/169100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-27 09:24 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/27/169100.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>foj 2072 Count錛堜簩鍒嗘煡鎵撅級http://www.shnenglu.com/cxiaojia/archive/2012/03/26/168991.htmlC灝忓姞C灝忓姞Mon, 26 Mar 2012 04:32:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/26/168991.htmlhttp://www.shnenglu.com/cxiaojia/comments/168991.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/26/168991.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/168991.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/168991.html

姣旇禌鐨勬椂鍊欐墜鍐欑殑浜屽垎錛屾繪槸RE銆傝竟鐣屽鐞嗙殑鑳藉姏榪樻湁寰呭姞寮恒?/span>

鐪嬩簡瑙i鎶ュ憡涔嬪悗鎰熻鑷繁寮辯垎浜嗭紝鐭ラ亾鏂規硶鐨勯閮藉啓涓嶅嚭鏉ャ傝屼笖褰撴椂榪樻槸鐢ㄧ殑map鍐欑殑錛屾偛鍓х殑瓚呮椂浜嗐傛敼鐢?/span>vector灝辮繃浜嗐?/span>

鎶婃瘡涓暟瀛楀嚭鐜扮殑浣嶇疆瀛樺偍涓嬫潵錛岀劧鍚庡鎵姹傜殑浣嶇疆榪涜涓ゆ浜屽垎錛屽氨OK浜嗐傜敤鐨勬槸stl閲岀殑浜屽垎錛屾病鎯沖埌榪唬鍣ㄨ繕鍙互榪欐牱鐢ㄣ?br />

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
 vector<int> m[100003];

int main()
{
    
    int n,q;
    while(scanf("%d %d",&n,&q)!=EOF)
    {
        for(int i=0;i<100003;++i)
            m[i].clear();
        int val,l,r,x;
        for(int i=1;i<=n;++i)
        {
            scanf("%d",&val);
            m[val].push_back(i);
        }
        for(int i=1;i<=q;i++)
        {
            scanf("%d %d %d",&l,&r,&x);
            if(m[x].size()!=0)
                if( *(--m[x].end())<l || *m[x].begin()>r )
                    printf("0\n");
                else
                {
                    int ans=( (--upper_bound(m[x].begin(),m[x].end(),r))-m[x].begin() )-( lower_bound(m[x].begin(),m[x].end(),l)-m[x].begin() )+1;
                    printf("%d\n",ans);
                }

            else printf("0\n");
        }
     }


    return 0;
}



C灝忓姞 2012-03-26 12:32 鍙戣〃璇勮
]]>
hdu 1069 Monkey and Banana NYOJ 232 錛堢畝鍗旸P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/23/168704.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Fri, 23 Mar 2012 02:37:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/23/168704.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/168704.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/23/168704.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/168704.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/168704.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">棰樻剰錛氭妸緇欏畾灝哄鐨勯暱鏂逛綋錛堟暟閲忎笉闄愶級鍙犲姞鍦ㄤ竴璧鳳紝鍙犲姞鐨勬潯浠舵槸錛屼笂闈竴涓暱鏂逛綋鐨勯暱鍜屽姣斾笅闈㈤暱鏂逛綋鐨勯暱鍜屽鐭紝涓嶈兘鐩哥瓑錛岄暱鏂逛綋鍙互浠繪剰闈㈡湞涓嬫憜鏀撅紝姹傝繖浜涢暱鏂逛綋鑳藉彔鍔犵殑鏈楂樼殑楂樺害銆?/span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">鎶婃瘡涓暱鏂逛綋鍒嗘垚</span>3<span style="font-family:瀹嬩綋;">涓厓绱犮傜劧鍚庡氨鍜岀煩褰㈠祵濂楀樊涓嶅浜嗭紝鎺掑簭涔嬪悗姹傚閲忔渶澶х殑瀛愬簭鍒椼?br /><br /><br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->    #include<iostream><br />    #include<cstdio><br />    #include<cstring><br />    #include<algorithm><br />    <span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><br />    typedef <span style="color: #0000FF; ">struct</span><br />    {<br />        <span style="color: #0000FF; ">int</span> l,w,h;<br />    }Cub;<br />    Cub cub[31*3];<br />    <span style="color: #0000FF; ">int</span> n;<br />    <span style="color: #0000FF; ">int</span> cnt;<br />    <span style="color: #0000FF; ">int</span> f[31*3];<br />    <span style="color: #0000FF; ">bool</span> cmp(Cub c1,Cub c2)<br />    {<br />        <span style="color: #0000FF; ">if</span>(c1.l==c2.l) <span style="color: #0000FF; ">return</span> c1.w<c2.w;<br />        <span style="color: #0000FF; ">return</span> c1.l<c2.l;<br />    }<br /><br />    <span style="color: #0000FF; ">bool</span> input()<br />    {<br />        scanf("%d",&n);<br />        <span style="color: #0000FF; ">if</span>(!n) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />        cnt=0;<br />        <span style="color: #0000FF; ">int</span> l,w,h;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;i++)<br />        {<br />            scanf("%d %d %d",&l,&w,&h);<br />            cub[cnt].h=l;<br />            cub[cnt].w=w>h?h:w;<br />            cub[cnt].l=w>h?w:h;<br />            cnt++;<br />            cub[cnt].h=w;<br />            cub[cnt].w=l>h?h:l;<br />            cub[cnt].l=l>h?l:h;<br />            cnt++;<br />            cub[cnt].h=h;<br />            cub[cnt].w=l>w?w:l;<br />            cub[cnt].l=l>w?l:w;<br />            cnt++;<br />        }<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />    }<br /><br />    <span style="color: #0000FF; ">void</span> DP()<br />    {<br />        memset(f,0,<span style="color: #0000FF; ">sizeof</span>(f));<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<cnt;i++) f[i]=cub[i].h;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<cnt;i++)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<i;j++)<br />            {<br />                <span style="color: #0000FF; ">if</span>((cub[i].l!=cub[j].l)&&(cub[i].w>cub[j].w))<br />                {<br />                    f[i]=max(f[i],f[j]+cub[i].h);<br />                }<br /><br />            }<br />        }<br />    }<br /><br />    <span style="color: #0000FF; ">void</span> print()<br />    {<br />        <span style="color: #0000FF; ">static</span> <span style="color: #0000FF; ">int</span> pos=0;<br />        <span style="color: #0000FF; ">int</span> ans=0;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<cnt;i++)<br />        ans=max(f[i],ans);<br />        printf("Case %d: maximum height = %d\n",++pos,ans);<br />    }<br /><br />    <span style="color: #0000FF; ">int</span> main()<br />    {<br />        <span style="color: #0000FF; ">while</span>(input())<br />        {<br />            sort(cub,cub+cnt,cmp);<br />            <span style="color: #008000; ">//</span><span style="color: #008000; ">for(int i=0;i<cnt;i++)<br />            </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    printf("%d %d %d\n",cub[i].l,cub[i].w,cub[i].h);</span><span style="color: #008000; "><br /></span>            DP();<br />            print();<br /><br /><br />        }<br /><br />        <span style="color: #0000FF; ">return</span> 0;<br />    }<br /><br />   </div><p> </p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/168704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-23 10:37 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/23/168704.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>NYOJ 110 鍓戝鍐蟲枟錛堢畝鍗旸P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/22/168576.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Thu, 22 Mar 2012 02:30:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/22/168576.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/168576.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/22/168576.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/168576.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/168576.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">緇嗚妭娌℃湁澶勭悊濂斤紝瀵艱嚧瓚呮椂浜嗗ソ澶氭銆?/span></p> <p><span style="font-family:瀹嬩綋;">瀵逛簬</span>i<span style="font-family:瀹嬩綋;">鍜?/span>j<span style="font-family:瀹嬩綋;">涓棿鐨?/span>k<span style="font-family:瀹嬩綋;">錛屽鏋?/span>i<span style="font-family:瀹嬩綋;">鍜?/span>j<span style="font-family:瀹嬩綋;">鑳介亣瑙?/span>k<span style="font-family:瀹嬩綋;">錛?/span>i<span style="font-family:瀹嬩綋;">鑳芥墦璐?/span>k<span style="font-family:瀹嬩綋;">鎴栬?/span>j<span style="font-family:瀹嬩綋;">鑳芥墦璐?/span>k<span style="font-family:瀹嬩綋;">錛屽垯</span>i<span style="font-family:瀹嬩綋;">灝辮兘閬囪</span>j<span style="font-family:瀹嬩綋;">錛岀敤</span>f[i][j]<span style="font-family:瀹嬩綋;">琛ㄧず</span>i<span style="font-family:瀹嬩綋;">鍜?/span>j<span style="font-family:瀹嬩綋;">鏄惁鑳介亣瑙併傚鏋?/span>i<span style="font-family:瀹嬩綋;">鏈緇堣兘閬囪鑷繁錛岄偅涔?/span>i<span style="font-family:瀹嬩綋;">灝辨湁鍙栧緱鑳滃埄鐨勫彲鑳姐?/span></p> <p><span style="font-family:瀹嬩綋;">娌℃湁寮澶ф暟緇勭殑蹇呰錛岀洿鎺ュ彇浣欏氨鍙互銆傚緱鐪嬫槑鐧介偅浜涙槸鏈浼樺瓙緇撴瀯錛屽惁鍒欎綘娌″姙娉?/span>DP<span style="font-family:瀹嬩綋;">銆?/span></p> <p><span style="font-family:瀹嬩綋;">鏃墮棿澶嶆潅搴︿負</span>O(n^3)<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">//</span><span style="color: #008000; ">NYOj110<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">Time:732 Memory:720</span><span style="color: #008000; "><br /></span>#include<iostream><br />#include<cstdio><br />#include<cstring><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">#include<></span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><br /><span style="color: #0000FF; ">bool</span> a[503][503];<br /><span style="color: #0000FF; ">bool</span> f[503][503];<br /><br /><br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #0000FF; ">int</span> t;<br />    scanf("%d",&t);<br />    <span style="color: #0000FF; ">while</span>(t--)<br />    {<br />        <span style="color: #0000FF; ">int</span> n;<br />        scanf("%d",&n);<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;i++)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<n;j++)<br />            {<br />                scanf("%d",&a[i][j]);<br />            }<br />        }<br />        memset(f,0,<span style="color: #0000FF; ">sizeof</span>(f));<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;i++)<br />        {<br />            f[i][(i+1)%n]=1;<br />        }<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=2;i<=n;i++)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<n;j++)<br />            {<br />                <span style="color: #0000FF; ">int</span> e=(j+i)%n;<br />                <span style="color: #0000FF; ">if</span>(f[j][e]) <span style="color: #0000FF; ">continue</span>;<br />                <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> k=(j+1)%n;k!=e;k++,k%=n)<br />                {<br />                    <span style="color: #0000FF; ">if</span>(f[j][k]&&f[k][e]&&(a[j][k]||a[e][k]))<br />                    {<br />                        f[j][e]=1;<br />                        <span style="color: #0000FF; ">break</span>;<br />                    }<br />                }<br />            }<br />        }<br />        <span style="color: #0000FF; ">int</span> ans=0;<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<n;i++)<br />        {<br />            <span style="color: #0000FF; ">if</span>(f[i][i]) ans++;<br />        }<br />        printf("%d\n",ans);<br />    }<br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/168576.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-22 10:30 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/22/168576.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>poj 2411 Mondriaan's Dream錛堢姸鎬佸帇緙〥P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/21/168534.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Wed, 21 Mar 2012 11:41:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/21/168534.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/168534.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/21/168534.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/168534.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/168534.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">鍙堟槸鍛ㄤ紵澶х墰璁烘枃閲岀殑渚嬮銆傛浘緇忓仛榪囦竴涓彧鏈変袱琛岀殑棰橈紝寰堟按鐨?/span>DP<span style="font-family:瀹嬩綋;">銆傜煩闃靛姞澶у悗鐘舵佷篃澧炲姞浜嗗緢澶氾紝寰堣嚜鐒剁殑灝辯敤鍒頒簡鐘舵佸帇緙┿?/span></p> <p><span style="font-family:瀹嬩綋;">浣嗘槸錛岀湅浜?/span>discuss<span style="font-family:瀹嬩綋;">涔嬪悗瑙夊緱鑷繁鍙堜竴嬈″急鐖嗕簡錛岄偅</span>25<span style="font-family:瀹嬩綋;">琛岀殑浠g爜鍐欑殑閮芥槸紲為┈鍟婏紝鐪嬫潵鍙湁鑶滄嫓鐨勪喚浜嗐傝繕鏄厛鍐欏ソ鐘舵佸帇緙╁惂銆?/span></p> <p><span style="font-family:瀹嬩綋;">璧峰垵鑷繁涓嶄細</span>DFS<span style="font-family:瀹嬩綋;">錛岀湅浜嗘煇浣嶅ぇ鐗涚殑瑙i鎶ュ憡錛岀悊瑙d簡</span>DFS<span style="font-family:瀹嬩綋;">騫朵笖琛ㄧず榪欎綅澶х墰鐨?/span>DFS<span style="font-family:瀹嬩綋;">鍐欑殑澶己澶т簡錛屽摝榪樻湁錛屽懆浼熷ぇ鐗涚殑璁烘枃澶己澶т簡錛屽摝榪樻病瀹岋紝鐘舵佸帇緙╁悗鐨勪簩榪涘埗琛ㄧず娉曞お寮哄ぇ浜嗭紝綆綆鍗曞崟鐨?/span>0<span style="font-family:瀹嬩綋;">鍜?/span>1<span style="font-family:瀹嬩綋;">灝辨妸鎵鏈夌殑鐘舵佸氨鎼炲畾浜嗐?/span></p> <p><span style="font-family:瀹嬩綋;">鍙戠幇</span>vector<span style="font-family:瀹嬩綋;">鍦ㄨ繖閲岀敤寰堝悎閫傘?/span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">澶х墰鍗氬鍦板潃錛?/span><a href="http://www.shnenglu.com/sdfond/archive/2009/07/31/91761.html">http://www.shnenglu.com/sdfond/archive/2009/07/31/91761.html</a></p> <p> </p> <p><span style="font-family:瀹嬩綋;">闅劇偣錛?/span>1<span style="font-family:瀹嬩綋;">銆?/span>DFS<span style="font-family:瀹嬩綋;">瀵繪壘鐘舵佺殑榪囩▼銆?/span>2<span style="font-family: 瀹嬩綋; background-color: highlight; ">銆佺姸鎬佸悜涓婂嚫鍑哄拰鍚戜笅鍑稿嚭鐨勫鐞嗐?br /><br /></span></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">//</span><span style="color: #008000; ">poj 2411<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">Time: 16MS Memory:1032K</span><span style="color: #008000; "><br /></span><br />#include<iostream><br />#include<cstdio><br />#include<vector><br />#include<cstring><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">int</span> m,n;<br />vector<<span style="color: #0000FF; ">int</span>> v[1<<11];<br /><span style="color: #0000FF; ">long</span> <span style="color: #0000FF; ">long</span> f[13][1<<11];<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">鍒濆鍖?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> init()<br />{<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<(1<<11);i++) v[i].clear();<br />    memset(f,0,<span style="color: #0000FF; ">sizeof</span>(f));<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">杈撳叆</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">bool</span> input()<br />{<br />    scanf("%d %d",&m,&n);<br />    <span style="color: #0000FF; ">if</span>(m<n) swap(m,n);<br />    <span style="color: #0000FF; ">if</span>(m&&n) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />    <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">瀵繪壘鐘舵?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> DFS(<span style="color: #0000FF; ">int</span> x,<span style="color: #0000FF; ">int</span> s1,<span style="color: #0000FF; ">int</span> s2)<span style="color: #008000; ">//</span><span style="color: #008000; ">s1鏄痵2鐨勪笂涓琛岀姸鎬?/span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(x>=n)<br />    {<br />        <span style="color: #0000FF; ">if</span>(s1<(1<<n)&&s2<(1<<n))<br />         v[s2].push_back(s1);<br />         <span style="color: #0000FF; ">return</span>;<br />    }<br />    DFS(x+1,s1<<1|1,s2<<1);<span style="color: #008000; ">//</span><span style="color: #008000; ">s1涓?錛宻2涓?琛ㄧず绔栫潃鎽嗘斁</span><span style="color: #008000; "><br /></span>    DFS(x+1,s1<<1,s2<<1|1);<span style="color: #008000; ">//</span><span style="color: #008000; ">s1涓?琛ㄧず绔栫潃鎽嗘斁鐨勪笅鍗婃錛宻2涓?琛ㄧず绔栫潃鎽嗘斁鐨勪笂鍗婃鍜屾í鐫鎽嗘斁鐨勫崐孌?/span><span style="color: #008000; "><br /></span>    DFS(x+2,s1<<2|3,s2<<2|3);<span style="color: #008000; ">//</span><span style="color: #008000; ">s1鍜宻2閮芥í鐫鎽嗘斁錛屾垨鑰卻1妯潃鏀?s2涓轟袱涓珫鐫鎽嗘斁鐨勪笂鍗婃</span><span style="color: #008000; "><br /></span>}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">DP</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> DP()<br />{<br />    <span style="color: #0000FF; ">int</span> total=1<<n;<br />    f[0][0]=1;<span style="color: #008000; ">//</span><span style="color: #008000; ">絎?琛岀殑鐘舵侊紝鍏?琛ㄧず姝よ宸茬粡琚崰婊★紝涓嶅厑璁哥涓琛屽悜涓婂嚫鍑?/span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=m+1;i++)<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<total;j++)<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> k=0;k<v[j].size();k++)<br />                f[i][j]+=f[i-1][v[j][k]];<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">杈撳嚭</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> print()<br />{<br />    printf("%I64d\n",f[m+1][(1<<n)-1]);<span style="color: #008000; ">//</span><span style="color: #008000; ">絎琺+1琛屼負鍏?鐘舵侊紝琛ㄧず絎琺琛屾病鏈夊嚫鍑烘潵鐨勭姸鎬併?/span><span style="color: #008000; "><br /></span>}<br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #0000FF; ">while</span>(input())<br />    {<br />        init();<br />        DFS(0,0,0);<br />        DP();<br />        print();<br /><br />    }<br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div><span style="font-family: 瀹嬩綋; "><br /><br /></span><p> </p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/168534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-21 19:41 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/21/168534.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>WA used long long,AC used __int64http://www.shnenglu.com/cxiaojia/archive/2012/03/21/168466.htmlC灝忓姞C灝忓姞Wed, 21 Mar 2012 01:37:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/21/168466.htmlhttp://www.shnenglu.com/cxiaojia/comments/168466.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/21/168466.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/168466.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/168466.html Because the server system is windows.

C灝忓姞 2012-03-21 09:37 鍙戣〃璇勮
]]>
poj 1185 鐐叺闃靛湴 錛堢姸鎬佸帇緙〥P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168435.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Tue, 20 Mar 2012 13:11:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168435.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/168435.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168435.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/168435.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/168435.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">寮辯垎浜嗐傛垜璋冭瘯浜嗕竴涓笅鍗堝姞鍗婁釜鏅氫笂錛屾渶鍚庨噸鍐欎簡涓閬?/span>AC<span style="font-family:瀹嬩綋;">浜嗐?/span>2xx ms<span style="font-family:瀹嬩綋;">鐨勬椂闂達紝鍦ㄨ嚜宸?/span>oj<span style="font-family:瀹嬩綋;">涓婃帓鍊掓暟絎竴銆?/span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">鎴戠殑絎簩閬撶姸鎬佸帇緙?/span>DP<span style="font-family:瀹嬩綋;">錛屼篃鏄懆浼熻鏂囥婄姸鎬佸帇緙┿嬮噷鐨勪竴閬撲緥棰橈紝鏍稿績鎬濇兂榪欑瘒璁烘枃鍒嗘瀽鐨勫緢娓呮錛屽緩璁涔犵姸鎬佸帇緙╃殑鍚屽涓瀹氳鐪嬩竴涓嬨?/span></p> <p> </p> <p><span style="font-family:瀹嬩綋;">榪欓亾棰樺仛鐨勫緢榪囩樉錛屾敹鑾峰緢澶氾紝鍚勭浜岃繘鍒剁殑瑙f硶銆傝繕鏈夌姸灝辨槸鎬佹暟鐨勬眰娉曚篃寰堝己錛屽垰寮濮嬪啓鐨勬椂鍊欒繕鍑嗗</span>DFS<span style="font-family:瀹嬩綋;">鍛紝鍚庢潵澶х墰鍛婅瘔鎴戠洿鎺ユ灇涓炬墍鏈夌姸鎬佽繘琛屽垹闄ゅ氨鍙互浜嗭紝濂藉惂錛屽垹闄ょ殑鍒ゆ柇鍙堟槸浜岃繘鍒躲?br /><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstring><br />#include<cstdio><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> MAXM=63;<br /><span style="color: #0000FF; ">int</span> e[103];<br /><span style="color: #0000FF; ">int</span> m,n;<br /><span style="color: #0000FF; ">int</span> s[MAXM];<br /><span style="color: #0000FF; ">int</span> c[MAXM];<br /><span style="color: #0000FF; ">int</span> f[103][MAXM][MAXM];<br /><span style="color: #0000FF; ">int</span> cnt;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">杈撳叆鏁版嵁</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> input()<br />{<br />    memset(e,0,<span style="color: #0000FF; ">sizeof</span>(e));<br />    <span style="color: #0000FF; ">char</span> str[13];<br /><br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<m;i++)<br />    {<br />        scanf("%s",str);<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<n;j++)<br />        {<br />            <span style="color: #0000FF; ">if</span>(str[j]=='H') e[i]=(e[i]<<1)|1;<br />            <span style="color: #0000FF; ">else</span> e[i]=e[i]<<1;<br />        }<br />    }<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">姣旇緝宸﹀彸闂撮殧鏄惁涓?</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">bool</span> fit(<span style="color: #0000FF; ">int</span> x)<br />{<br />    <span style="color: #0000FF; ">if</span>( x & (x<<1) ) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />    <span style="color: #0000FF; ">if</span>( x & (x<<2) ) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<br />    <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">浜岃繘鍒朵腑1鐨勪釜鏁?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">int</span> num1(<span style="color: #0000FF; ">int</span> x)<br />{<br />    <span style="color: #0000FF; ">int</span> count=0;<br />    <span style="color: #0000FF; ">while</span>(x>0)<br />    {<br />        count++;<br />        x= x & (x-1);<br />    }<br />    <span style="color: #0000FF; ">return</span> count;<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">瀵繪壘鐘舵佹暟</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> DFS()<br />{<br />    <span style="color: #0000FF; ">int</span> total=1<<n;<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<total;i++)<br />    {<br />        <span style="color: #0000FF; ">if</span>(fit(i))<br />        {<br />            s[++cnt]=i;<br />            c[cnt]=num1(i);<br />        }<br />    }<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">DP</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> DP()<br />{<br />    <span style="color: #008000; ">//</span><span style="color: #008000; ">鍒濆鍖?/span><span style="color: #008000; "><br /></span>    memset(f,-1,<span style="color: #0000FF; ">sizeof</span>(f));<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<=cnt;++i)<br />    {<br />        <span style="color: #0000FF; ">if</span>(s[i]&e[0])<span style="color: #0000FF; ">continue</span>;<br />        f[0][i][0]=c[i];<br />    }<br /><br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<m;++i)<br />    {<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<=cnt;++j)<br />        {<br />            <span style="color: #0000FF; ">if</span>(s[j]&e[i])<span style="color: #0000FF; ">continue</span>;<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> k=0;k<=cnt;++k)<br />            {<br />                <span style="color: #0000FF; ">if</span>(s[j]&s[k])<span style="color: #0000FF; ">continue</span>;<br />                <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> l=0;l<=cnt;++l)<br />                {<br />                    <span style="color: #0000FF; ">if</span>(s[j]&s[l]) <span style="color: #0000FF; ">continue</span>;<br />                    <span style="color: #0000FF; ">if</span>(f[i-1][k][l]==-1) <span style="color: #0000FF; ">continue</span>;<br />                    f[i][j][k]=max(f[i][j][k],f[i-1][k][l]+c[j]);<br />                }<br />            }<br />        }<br />    }<br />}<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">杈撳嚭</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> print()<br />{<br />    <span style="color: #0000FF; ">int</span> ans=0;<br />    <span style="color: #0000FF; ">if</span>(m!=0)<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=0;i<=cnt;i++)<br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=0;j<=cnt;j++)<br />            ans=max(ans,f[m-1][i][j]);<br />    printf("%d\n",ans);<br />}<br /><br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #008000; ">//</span><span style="color: #008000; ">freopen("in.txt","r",stdin);</span><span style="color: #008000; "><br /></span><br />    <span style="color: #0000FF; ">while</span>(scanf("%d %d",&m,&n)!=EOF)<br />    {<br />        cnt=-1;<br />        input();<br />        DFS();<br />        DP();<br />        print();<br /><br />    }<br /><br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div><span style="font-family:瀹嬩綋;"><br /></span></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/168435.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-20 21:11 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168435.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>sgu 223 Little Kings錛堢姸鎬佸帇緙〥P錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168375.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Tue, 20 Mar 2012 03:34:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168375.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/168375.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168375.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/168375.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/168375.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">絎竴涓姸鎬佸帇緙╁晩錛岃皟璇曚簡涓涓笂鍗堬紝緇堜簬榪囦簡錛屽浗鐜嬬殑涓暟鍘熸潵鏄粠</span>0<span style="font-family:瀹嬩綋;">寮濮嬪驚鐜殑銆?/span></p> <p><span style="font-family:瀹嬩綋;">鍛ㄤ紵澶х鐨勮鏂囥婄姸鎬佸帇緙┿嬪緢緇欏姏錛屽鏋滀笉鏄繖綃囪鏂囷紝鎴戦兘涓嶇煡閬撹濡備綍鍏ラ棬浜嗐傚搸錛屾病浜烘暀鐨勬澂鍏楓?/span></p> <p><span style="font-family:瀹嬩綋;">鏈棰樿В銆婄姸鎬佸帇緙┿嬭鐨勫緢娓呮錛屾垜灝變笉澶氬簾璇濅簡銆傞渶瑕佹敞鎰忕殑鏄寖鍥翠細瓚?/span>int<span style="font-family:瀹嬩綋;">錛岃繕鏈夊鐘舵佺殑鑼冨洿瑕佹妸鎻″ソ錛屾悶涓嶅ソ浣犱篃瑕佹澂鍏峰幓鍚勭璋冭瘯浜嗐?/span></p> <p><span style="font-family:瀹嬩綋;">鑷繁鍐欑殑</span>DFS<span style="font-family:瀹嬩綋;">寰堟尗錛屽熺敤浜嗕笉鐭ラ亾鍝綅澶х墰鐨?/span>DFS<span style="font-family:瀹嬩綋;">銆?br /><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstring><br />#include<cstdio><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">const</span> <span style="color: #0000FF; ">int</span> MAXM=520;<br /><span style="color: #0000FF; ">int</span> n,k;<br /><span style="color: #0000FF; ">int</span> s[MAXM];<span style="color: #008000; ">//</span><span style="color: #008000; ">鐘舵佹暟</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">int</span> c[MAXM];<span style="color: #008000; ">//</span><span style="color: #008000; ">1鐨勪釜鏁?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">long</span> <span style="color: #0000FF; ">long</span> f[13][MAXM][103];<br /><span style="color: #0000FF; ">int</span> ck;<br /><span style="color: #0000FF; ">void</span> dfs(<span style="color: #0000FF; ">int</span> x,<span style="color: #0000FF; ">int</span> val,<span style="color: #0000FF; ">int</span> cnt)<span style="color: #008000; ">//</span><span style="color: #008000; ">DFS瀵繪壘姣忚鐨勭姸鎬佹暟</span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(x==n)<br />    {<br />        s[++ck]=val;<br />        c[ck]=cnt;<br />        <span style="color: #0000FF; ">return</span>;<br />    }<br />    dfs(x+1,val<<1,cnt);<br />    <span style="color: #0000FF; ">if</span>(!(val&1))<br />    dfs(x+1,val<<1|1,cnt+1);<br />}<br /><span style="color: #0000FF; ">bool</span> cont(<span style="color: #0000FF; ">int</span> s1,<span style="color: #0000FF; ">int</span> s2)<span style="color: #008000; ">//</span><span style="color: #008000; ">鍒ゆ柇涓庨鎰忔槸鍚︾煕鐩?/span><span style="color: #008000; "><br /></span>{<br />    <span style="color: #0000FF; ">if</span>(s1&s2) <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<span style="color: #008000; ">//</span><span style="color: #008000; ">鍜屾涓婃柟鍒ゆ柇</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">if</span>(s1&(s2<<1))<span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<span style="color: #008000; ">//</span><span style="color: #008000; ">鍜屽彸涓婃柟鍒ゆ柇</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">if</span>(s1&(s2>>1))<span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">false</span>;<span style="color: #008000; ">//</span><span style="color: #008000; ">鍜屽乏涓婃柟鍒ゆ柇</span><span style="color: #008000; "><br /></span>    <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">true</span>;<br />}<br /><span style="color: #0000FF; ">void</span> dp()<br />{<br />        <span style="color: #008000; ">//</span><span style="color: #008000; ">鍒濆鍖栫姸鎬?/span><span style="color: #008000; "><br /></span>        memset(f,0,<span style="color: #0000FF; ">sizeof</span>(f));<br />        f[0][1][0]=1;<br />        <span style="color: #008000; ">//</span><span style="color: #008000; ">dp</span><span style="color: #008000; "><br /></span>        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=n;i++)<br />        {<br />            <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> j=1;j<=ck;j++)<br />            {<br />                <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> g=1;g<=ck;g++)<br />                {<br />                    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> p=0;p<=k;p++)<br />                    {<br />                        <span style="color: #0000FF; ">if</span>((p-c[j]>=0)&&cont(s[j],s[g]))<br />                        f[i][j][p]+=f[i-1][g][p-c[j]];<br />                    }<br />                }<br />            }<br />        }<br />}<br /><br /><span style="color: #0000FF; ">int</span> main()<br />{<br />    <span style="color: #0000FF; ">while</span>(scanf("%d %d",&n,&k)!=EOF)<br />    {<br />        ck=0;<br />        dfs(0,0,0);<br />        dp();<br />        <span style="color: #0000FF; ">long</span> <span style="color: #0000FF; ">long</span> ans=0;<br />        <br />        <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=1;i<=ck;++i)<br />        {<br />            ans+=f[n][i][k];<br />        }<br /><br />        printf("%I64d\n",ans);<br /><br />    }<br /><br /><br />    <span style="color: #0000FF; ">return</span> 0;<br />}<br /></div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/168375.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-20 11:34 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/20/168375.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>NYOJ 475 Doctor's order (閫嗗簭鏁?http://www.shnenglu.com/cxiaojia/archive/2012/03/19/168314.htmlC灝忓姞C灝忓姞Mon, 19 Mar 2012 05:43:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/19/168314.htmlhttp://www.shnenglu.com/cxiaojia/comments/168314.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/19/168314.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/168314.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/168314.html

澶ф剰錛氫袱涓瀭鐩翠簬x杞寸殑鐩寸嚎lx鍜?/span>rx鍥存垚鐨勫尯鍩熴傛湁n鏉$洿綰跨┛榪囪繖鐗囧尯鍩燂紝姣忔潯鐩寸嚎yi=kxi+b錛岀粰鍑?/span>k鍜?/span>b銆傛眰鐩寸嚎鎶婅繖涓尯鍩熷垎鎴愪簡鍑犱釜閮ㄥ垎銆備笁鏉$洿綰夸笉浼氫氦浜庝竴鐐癸紙鍖呮嫭錛氫袱涓瀭鐩翠簬x杞寸殑鐩寸嚎錛夈?/span>

鐢誨浘鍙互鎵懼嚭涓縐嶅叧緋伙紝鍒嗘垚鐨勫尯鍩熸暟=浜ょ偣鏁?/span>+綰挎鏁?/span>+1錛涘宸︾鐐逛粠澶у埌灝忔帓搴忥紝鐒跺悗瀵瑰彸绔偣姹傞嗗簭鏁幫紝閫嗗簭鏁板氨鏄氦鐐規暟錛岀嚎孌墊暟宸茬煡錛岀┖闂存暟灝卞嚭鏉ヤ簡銆?/span>



#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXM=30004;
const int INF=0x7fffffff-1;
typedef struct
{
    int y1,y2;
}Line;
Line line[MAXM];
int temp1[MAXM/2+1];
int temp2[MAXM/2+1];
int cnt;
bool cmp(Line l1,Line l2)
{
    return l1.y1>l2.y1;
}
void merge(int start,int mid,int end)
{
    int n1,n2;
    n1=mid-start+1;
    n2=end-mid;
    for(int i=0;i<n1;i++)
    temp1[i]=line[start+i].y2;
    for(int i=0;i<n2;i++)
    temp2[i]=line[mid+i+1].y2;
    temp1[n1]=-INF;
    temp2[n2]=-INF;
    for(int k=start,i=0,j=0;k<=end;k++)
    {
        if(temp1[i]>=temp2[j])
        {
            line[k].y2=temp1[i];
            i++;
        }
        else
        {
            cnt+=n1-i;//姹傞嗗簭鏁?/span>
            line[k].y2=temp2[j];
            j++;
        }
    }

}
//褰掑茍鎺掑簭
void mergesort(int start,int end)
{
    if(start>=end) return;
    int mid=(end+start)/2;
    mergesort(start,mid);
    mergesort(mid+1,end);
    merge(start,mid,end);

}

int main()
{
    int lx,rx;
    while(scanf("%d%d",&lx,&rx)!=EOF)
    {
        cnt=0;
        int n,k,b;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&k,&b);
            line[i].y1=lx*k+b;
            line[i].y2=rx*k+b;

        }
        sort(line,line+n,cmp);//瀵瑰乏绔偣浠庡ぇ鍒板皬鎺掑簭
        mergesort(0,n-1);
        printf("%d\n",cnt+n+1);//絀洪棿鏁?浜ょ偣鏁?綰挎鏁?1

    }
    return 0;
}



C灝忓姞 2012-03-19 13:43 鍙戣〃璇勮
]]>
zoj 3578 NYOJ 472 Matrix 錛堟按棰橈級http://www.shnenglu.com/cxiaojia/archive/2012/03/19/168313.htmlC灝忓姞C灝忓姞Mon, 19 Mar 2012 05:36:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/19/168313.htmlhttp://www.shnenglu.com/cxiaojia/comments/168313.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/19/168313.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/168313.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/168313.html

涓鐩磋涓烘槸浜岀淮綰挎鏍戯紝鐪嬩簡瑙i鎶ュ憡鍚庡眳鐒舵槸姘撮銆?/span>

 

鏈澶?/span>1000涓煩褰€傛瘡嬈℃壂鎻忕煩褰笌涔嬪墠鐨勭煩褰㈡槸鍚︾浉浜わ紝鍦ㄧ浉浜ょ殑鐭╁艦涓壘鍒頒竴涓渶澶х殑鍊?/span>max錛岃榪欎釜max鍔犱笂h灝辨槸榪欐鐭╁艦鐨勫箋傛瘡嬈″悜鍥炴壂鎻忎竴閬嶏紝鏈楂樹篃灝?/span>1000*1000鐨勬椂闂達紝1s鍐呯粷瀵規病闂銆?br />

#include<iostream>
#include<cstdio>
using namespace std;

typedef struct
{
    int x1,y1,x2,y2,_max;
}Matrix;
Matrix matrix[1003];

bool cover(int i,int j)//鏄惁鐩鎬氦
{
    if(matrix[i].x1>=matrix[j].x2||matrix[j].x1>=matrix[i].x2) return false;
    if(matrix[i].y1>=matrix[j].y2||matrix[j].y1>=matrix[i].y2) return false;
    return true;
}

int main()
{
    int N,M,C;
    while(scanf("%d %d %d",&N,&M,&C)!=EOF)
    {
        int ans=0;
        int a,b,h,x,y;
        for(int i=0;i<C;i++)
        {
            int tmax=0;
            scanf("%d %d %d %d %d",&a,&b,&h,&x,&y);
            matrix[i].x1=x;
            matrix[i].y1=y;
            matrix[i].x2=x+a;
            matrix[i].y2=y+b;
            for(int j=i-1;j>=0;j--)
            {
                if(cover(i,j))
                {
                    tmax=max(tmax,matrix[j]._max);
                }

            }
            matrix[i]._max=tmax+h;
            ans=max(ans,matrix[i]._max);
        }
        printf("%d\n",ans);
    }
    return 0;
}



C灝忓姞 2012-03-19 13:36 鍙戣〃璇勮
]]>
Ural1117. Hierarchy錛堟妧宸ч錛學A浜嗗ソ澶氭錛?/title><link>http://www.shnenglu.com/cxiaojia/archive/2012/03/14/167838.html</link><dc:creator>C灝忓姞</dc:creator><author>C灝忓姞</author><pubDate>Wed, 14 Mar 2012 00:48:00 GMT</pubDate><guid>http://www.shnenglu.com/cxiaojia/archive/2012/03/14/167838.html</guid><wfw:comment>http://www.shnenglu.com/cxiaojia/comments/167838.html</wfw:comment><comments>http://www.shnenglu.com/cxiaojia/archive/2012/03/14/167838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/cxiaojia/comments/commentRss/167838.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/cxiaojia/services/trackbacks/167838.html</trackback:ping><description><![CDATA[<div><p><span style="font-family:瀹嬩綋;">榪欓亾棰樼籂緇撴垜浜嗕竴澶╃殑鏃墮棿錛屾湰浠ヤ負鐢?/span>lowbit<span style="font-family:瀹嬩綋;">鍙互杞繪澗鎼炲畾錛屽彲鏄腑闂村嚭鐜頒簡鍚勭鏁呴殰錛?/span>WA<span style="font-family:瀹嬩綋;">浜嗗緢澶氭鎵?/span>AC<span style="font-family:瀹嬩綋;">銆?/span></p> <p><span style="font-family:瀹嬩綋;">璁$畻</span>a<span style="font-family:瀹嬩綋;">鍜?/span>b<span style="font-family:瀹嬩綋;">涔嬮棿鐨勮妭鐐規暟錛屽彲浠ョ敤</span>1-a<span style="font-family:瀹嬩綋;">涓?/span>1-b<span style="font-family:瀹嬩綋;">鐨勮妭鐐規暟涔嬪樊鏉ユ眰銆傚湪鍙沖瓙鏍戠殑鐐瑰彲浠ヨ漿鍖栦負鐩稿簲鐨勫乏瀛愭爲鐨勭偣錛岀粡榪囧姝ラ鐨勮漿鍖栵紝鍙互鎶婄偣鐨勪綅緗浐瀹氬湪鏍戠殑鏈宸﹁竟鐨勯偅鏉$嚎涓娿傛墍浠ュ彧闇瑕佽綆楁瘡灞傛渶宸﹁竟鐨勮妭鐐規暟灝?/span>OK<span style="font-family:瀹嬩綋;">浜嗐傜粡榪囬掓帹浼氬緱鍑轟竴涓叕寮忥紝</span>z[i]=z[i-1]*2+i-1;i<span style="font-family:瀹嬩綋;">琛ㄧず鏍戠殑楂樺害銆?br /><br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include<iostream><br />#include<cstdio><br />#include<cmath><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br />typedef <span style="color: #0000FF; ">long</span> <span style="color: #0000FF; ">long</span> ll;<br />ll z[33]={0};<span style="color: #008000; ">//</span><span style="color: #008000; ">浠?鍒皀緇忚繃鐨勭偣</span><span style="color: #008000; "><br /></span>ll d[33]={0};<span style="color: #008000; ">//</span><span style="color: #008000; ">鏍戞瘡灞傛渶宸﹁竟鐨勫簭鍙?/span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">void</span> init()<br />{<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=2;i<=31;i++)<br />    {<br />        z[i]=z[i-1]*2+i-1;<br />    }<br />    d[1]=1;<br />    <span style="color: #0000FF; ">for</span>(<span style="color: #0000FF; ">int</span> i=2;i<=31;i++)<br />    {<br />        d[i]=d[i-1]<<1;<br />    }<br />}<br />ll lowbit(ll x)<br />{<br />    <span style="color: #0000FF; ">return</span> x&(-x);<br />}<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">寰楀埌鏁扮殑浜岃繘鍒朵綅鏁?/span><span style="color: #008000; "><br /></span>ll getbit(ll x)<br />{<br />    ll cnt=0;<br />    <span style="color: #0000FF; ">while</span>(x!=1)<br />    {<br />        x>>=1;<br />        cnt++;<br />    }<br />    <span style="color: #0000FF; ">return</span> cnt;<br />}<br /><span style="color: #0000FF; ">void</span> swap(<span style="color: #0000FF; ">int</span>& a,<span style="color: #0000FF; ">int</span>& b)<br />{<br />    <span style="color: #0000FF; ">int</span> temp=a;<br />    a=b;<br />    b=temp;<br />}<br />ll fun(ll x)<br />{<br />    <span style="color: #0000FF; ">return</span> d[getbit(x)+1];<span style="color: #008000; ">//</span><span style="color: #008000; ">寰楀埌浣嶆暟瀵瑰簲鐨勪簩榪涘埗鏁?/span><span style="color: #008000; "><br /></span>}<br />ll solve(ll x)<br />{<br />   ll bx=x-lowbit(x);<br />    <span style="color: #0000FF; ">if</span>(bx==0)<br />    {<br />        <span style="color: #0000FF; ">return</span> z[getbit(x)];<br />    }<br />    <span style="color: #0000FF; ">else</span><br />    {<br /><br />        <span style="color: #0000FF; ">int</span> temp=fun(x);<br />        ll sum=solve(temp)+abs(solve(temp)-solve(temp-(x-temp)));<br /><br />        <span style="color: #0000FF; ">return</span> sum;<br />    }<br />}<br /><br /><br /><span style="color: #0000FF; ">int</span> main()<br />{<br />init();<br />    <span style="color: #0000FF; ">int</span> a,b;<br />    <span style="color: #0000FF; ">while</span>(scanf("%d %d",&a,&b)!=EOF)<br />    {<br /><br />        <span style="color: #0000FF; ">if</span>(a>b) swap(a,b);<br />        ll ba=solve(a);<br />        ll bb=solve(b);<br />        printf("%lld\n",bb-ba);<br />    }<br />    <span style="color: #0000FF; ">return</span> 0;<br />}</div></p></div><img src ="http://www.shnenglu.com/cxiaojia/aggbug/167838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/cxiaojia/" target="_blank">C灝忓姞</a> 2012-03-14 08:48 <a href="http://www.shnenglu.com/cxiaojia/archive/2012/03/14/167838.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Ural 1071. Nikifor 2 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/03/08/167407.htmlC灝忓姞C灝忓姞Thu, 08 Mar 2012 07:47:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/08/167407.htmlhttp://www.shnenglu.com/cxiaojia/comments/167407.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/08/167407.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/167407.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/167407.html浠巏=2寮濮嬫灇涓撅紝涓鐩存灇涓懼埌x銆?br />
#include<iostream>
#include<cstdio>
using namespace std;


bool comp(int x,int y,int k)
{
        int temp1,temp2;
        while(y!=0)
        {
            temp1=y%k;
            y/=k;
            while(x!=0)
            {
                temp2=x%k;
                if(temp1==temp2)
                break;
                x/=k;
            }
            if(x==0) return false;
            x/=k;
        }

        return true;
}


int main()
{
        int x,y;
        scanf("%d %d",&x,&y);
        int k=2;
        for(;k<=x;k++)
        {
            if(comp(x,y,k)) break;
        }
        if(k>x) printf("No solution\n");
        else printf("%d\n",k);
        return 0;
}


C灝忓姞 2012-03-08 15:47 鍙戣〃璇勮
]]>
hdu 4163 Stock Prices 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/03/06/167228.htmlC灝忓姞C灝忓姞Tue, 06 Mar 2012 02:48:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/06/167228.htmlhttp://www.shnenglu.com/cxiaojia/comments/167228.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/06/167228.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/167228.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/167228.html

姘撮銆?/span>

棰樻剰錛氱粰浣犳瘡澶╃殑鑲′環錛岃浣犳壘鍑烘渶灝忕殑K1涓偂浠鳳紝鐒跺悗鎸夋棩鏈熶粠灝忓埌澶ф帓搴忚緭鍑猴紝鎵懼嚭鏈澶х殑k2涓偂浠鳳紝鎸夋棩鏈熶粠澶у埌灝忚緭鍑恒?/span>

 

鎴戠敤浜?/span>4涓?/span>sort銆?br />

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef struct
{
    int p,d;
}Data;
Data dt[1000003];

bool cmp1(Data d1,Data d2)
{
    if(d1.p==d2.p) return d1.d<d2.d;
    return d1.p<d2.p;
}
bool cmp2(Data d1,Data d2)
{
    if(d1.p==d2.p) return d1.d>d2.d;
    return d1.p>d2.p;
}
bool cmp3(Data d1,Data d2)
{
     return d1.d<d2.d;
}
bool cmp4(Data d1,Data d2)
{
     return d1.d>d2.d;
}
void print()
{
    static int cnt=0;
    printf("Case %d\n",++cnt);
}
int main()
{
    int n,k1,k2;
    while(scanf("%d %d %d",&n,&k1,&k2),n&&k1&&k2)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&dt[i].p);
            dt[i].d=i+1;
        }
        sort(dt,dt+n,cmp1);//浠庡皬鍒板ぇ鎺掑簭
        print();//蹇界暐
        sort(dt,dt+k1,cmp3);//鏃ユ湡鐨勫瓧鍏稿簭浠庡皬鍒板ぇ
        printf("%d",dt[0].d);
        for(int i=1;i<k1;i++)
        printf(" %d",dt[i].d);
        printf("\n");
        sort(dt,dt+n,cmp2);//浠庡ぇ鍒板皬鎺掑簭
        sort(dt,dt+k2,cmp4);//鏃ユ湡鐨勫瓧鍏稿簭浠庡ぇ鍒板皬
        printf("%d",dt[0].d);
        for(int i=1;i<k2;i++)
        printf(" %d",dt[i].d);
        printf("\n");

    }
    return 0;
}

 



C灝忓姞 2012-03-06 10:48 鍙戣〃璇勮
]]>
hdu 4165 Pills 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/03/05/167167.htmlC灝忓姞C灝忓姞Mon, 05 Mar 2012 05:49:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/05/167167.htmlhttp://www.shnenglu.com/cxiaojia/comments/167167.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/05/167167.html#Feedback3http://www.shnenglu.com/cxiaojia/comments/commentRss/167167.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/167167.html

DP鎴栧崱鐗瑰叞鏁?span style="font-family:瀹嬩綋;">銆?/span>

寮辯垎浜嗐傚仛棰樼殑鏃跺欏彧鎯崇潃鐢ㄤ竴涓姸鎬佸幓鍋氾紝緇撴灉鎮插墽浜嗐傚悗鏉ユ垚鍝ユ彁閱掔敤浜岀淮鐨勶紝鎴戞墠鍙戠幇寰楃敤涓や釜鐘舵佸幓鍐欍傚搸錛屾庝箞娌℃兂鍒頒袱涓姸鎬佸憿銆?br />棰樻剰錛氬湪涓涓摱瀛愰噷鏈塏鐗囪嵂錛屾瘡嬈″悆鍗婄墖錛屼粠鐡跺瓙閲屽彲鑳芥嬁鍑烘暣鐗囷紝涔熷彲鑳芥嬁鍑哄崐鐗囷紝濡傛灉鎷垮嚭鏁寸墖錛岃涓篧錛屽崐鐗囪涓篐銆傞棶鏈夊灝戠鎺掑垪銆?/span>

絎竴涓姸鎬侊細瀹屾暣鑽墖鐨勬暟閲忋傜浜屼釜鐘舵侊細鍗婄墖鑽墖鐨勬暟閲忋?/span>

F錛?/span>i錛?/span>j錛?/span>=f錛?/span>i-1,j+1錛?/span>+f錛?/span>I錛?/span>j-1錛夛紱

褰撳悆鐨勬槸鏁寸墖鏃訛紝i-1錛屽崐鐗囩殑澧炲姞涓涓紝j+1銆?/span>

褰撳悆鐨勬槸鍗婄墖鏃訛紝i涓嶅彉錛?/span>j-1銆?/span>

鐢ㄤ袱涓姸鎬佸啓鐨勬椂鍊欒繖涓灝卞緢姘翠簡銆備笉榪囨彁浜ょ殑鏃跺欏湪g++涓嬬敤lang lang WA錛屾敼鎴?/span>int64鍦?/span>C++涓嬫彁浜ゅ氨AC浜嗐傚緢鏄笉瑙c?br />
鍗$壒鍏版暟鐨勬柟娉曞氨涓嶅璇翠簡銆傘傘傘備綘鎳傜殑銆傘?/span>

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
__int64 f[33][33];

int main()
{
    memset(f,0,sizeof(f));
    int k=30;
    for(int i=0;i<k;i++) f[1][i]=i+1;
    for(int i=2;i<=30;i++)
    {
        k--;
        f[i][0]=f[i-1][1];
        for(int j=1;j<k;j++)
        {
            f[i][j]=f[i][j-1]+f[i-1][j+1];
        }
    }


   int s;
   while(scanf("%d",&s),s)
   {
       printf("%I64d\n",f[s][0]);
   }
    return 0;
}

 



C灝忓姞 2012-03-05 13:49 鍙戣〃璇勮
]]>
Ural 1098. Questions 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/03/02/166995.htmlC灝忓姞C灝忓姞Fri, 02 Mar 2012 09:09:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/02/166995.htmlhttp://www.shnenglu.com/cxiaojia/comments/166995.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/02/166995.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/166995.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166995.html

棰樼湅涓嶆噦錛屽湪緗戜笂鎵懼埌鐨勭炕璇戙傚氨鏄暣涓覆錛堜笉鏄暣琛岋級鐨勭害鐟熷か鐜?br />

#include<iostream>
#include<cstdio>
 using namespace std;

char str[30003];
int Josephus(int n,int m,int k ) //鍒嗗埆涓猴細浜烘暟錛屽嚭鍦堟闀匡紝璧蜂嬌鎶ユ暟浣嶇疆,
 {
     int x=1;
     
     if (m == 1)
         k = k == 1 ? n : (k + n - 1) % n;
             else{
                 for (int i = 1; i <= n; i++)
                 {
                     if ((k + m) < i)
                     {
                         x = (i - k + 1) / (m - 1) - 1;
                         if (i + x < n){
                             i = i + x;
                             k = (k + m * x);
                         }
                         else{
                             k = k + m * (n - i) ;
                             i = n;
                         }
                    }
                    k = (k + m - 1) % i + 1;
                }
           }
      return k; //榪斿洖鏈鍚庝竴浜虹殑浣嶇疆
 }

 int main()
 {
     //freopen("in.txt","r",stdin);
     int len=0;
    while(scanf("%c",&str[0])!=EOF)
    {
        if(str[0]>=' ')
        str[++len]=str[0];
    }
    int k=Josephus(len,1999,1);
    if (str[k]=='?')
    printf("Yes\n");
    else if (str[k]==' ')
    printf("No\n");
     else
      printf("No comments\n");


     return 0;
 }

 



C灝忓姞 2012-03-02 17:09 鍙戣〃璇勮
]]>
Ural1095. Nikifor 3 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/03/01/166858.htmlC灝忓姞C灝忓姞Thu, 01 Mar 2012 05:50:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/03/01/166858.htmlhttp://www.shnenglu.com/cxiaojia/comments/166858.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/03/01/166858.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/166858.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166858.html

棰樼洰淇濊瘉鑷沖皯鏈変竴涓?/span>1銆?/span>2銆?/span>3銆?/span>4銆傝鏄庤繖鍥涗釜鏁版槸涓涓獊鐮寸偣銆傜敱姝ゅ彲浠ヨ仈鎯沖埌浠?/span>1銆?/span>2銆?/span>3銆?/span>4鍥涗釜鏁板瓧緇撳熬鐨勬暟淇濊瘉鑳借7鏁撮櫎銆傝繖鏍蜂笉璁哄墠杈圭殑鏁版庢牱鎺掑垪錛屽悗杈瑰洓涓暟鎬繪湁涓縐嶇粍鍚堣兘澶熶繚璇佹暣浣撳彲浠ヨ7鏁撮櫎銆?br />

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int z[7]={4123,1324,1234,2341,1243,3421,3142};
char s[23];
int ns[23];
int num0_9[10];
int atoi(char s)
{
    return s-'0';
}
int fun(int x,int num)//鎶婂墠杈圭殑鏁版帓鍒楁垚鏂版暟
{
    for(int i=0;i<num0_9[num];i++)
    {
        ns[x+i]=num;
    }
    return x+num0_9[num];
}
int fun2(int x)//姹傚墠杈圭殑鏁伴櫎浠?鐨勪綑鏁?/span>
{
    int yu=0;
    for(int i=0;i<x;i++)
    {
        yu=(yu*10+ns[i])%7;
    }
    return yu;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(num0_9,0,sizeof(num0_9));
        scanf("%s",s);
        int slen=strlen(s);
        //緇熻姣忎釜鏁扮殑涓暟
        for(int i=0;i<slen;i++)
        {
          int num=atoi(s[i]);
          num0_9[num]++;
        }
        //鍑忓幓1銆?銆?銆?
        for(int i=1;i<=4;i++)
        {
            num0_9[i]--;
        }
        //姹傚墠杈圭粍鎴愮殑鏂版暟
        int x=0;
        for(int i=1;i<=9;i++)
        {
            x=fun(x,i);
        }
        int yu=fun2(x);//姹傛柊鏁伴櫎浠?鐨勪綑鏁?/span>
        int i;
        //鎵懼埌涓縐嶇粍鍚堝彲浠ヤ笌鍓嶈竟鐨勬暟緇勫悎璧鋒潵琚?鏁撮櫎
        for(i=0;i<7;i++)
        {
            if((yu*10000+z[i])%7==0)
            {
                break;
            }
        }
        //杈撳嚭錛屽悗杈瑰彲浠ヨˉ涓?
        for(int j=0;j<x;j++)
        printf("%d",ns[j]);
        printf("%d",z[i]);
        for(int j=0;j<num0_9[0];j++)
        printf("0");
        printf("\n");

    }

    return 0;
}

 



C灝忓姞 2012-03-01 13:50 鍙戣〃璇勮
]]>
zoj 3576 NYOJ 470 Count the Length 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/02/29/166812.htmlC灝忓姞C灝忓姞Wed, 29 Feb 2012 13:03:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/02/29/166812.htmlhttp://www.shnenglu.com/cxiaojia/comments/166812.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/02/29/166812.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/166812.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166812.html

綆鍗曟暟瀛︺?/span>

棰樻剰鏄粰瀹氶暱鍜屽錛屾眰瀵硅綰跨孩鑹插尯鍩熺殑闀垮害鍜屻?/span>

鎶?/span>m,n閮介櫎浠ヤ粬浠殑鏈澶у叕綰︽暟t錛屼嬌tm=m/t,tn=n/t錛屾柊tm錛?/span>tn鎵緇勬垚鐨勭煩褰㈢殑瀵硅綰塊暱搴?/span>*t灝辨槸鍘熺煩褰㈢殑瀵硅綰塊暱搴︺?/span>

鎶婂瑙掔嚎騫沖潎鍒嗘垚tm*tn鏉$嚎孌碉紝瀵硅綰夸笌姣忔潯綰挎鐨勪氦鐐瑰繀鍦?/span>tm*tn浠戒腑鐨勭嚎孌電殑绔偣涓婏紙鍙埄鐢ㄧ浉浼間笁瑙掑艦璇佹槑錛岃繖閲岀渷鐣ワ級銆?/span>

瑙傚療鍙互鐪嬪嚭濡傛灉tm鍜?/span>tn鏈変竴涓槸鍋舵暟錛屽垯綰㈣壊綰挎鐨勬暟閲忓拰钃濊壊綰挎鐨勬暟閲忕浉絳夛紝濡傛灉tm鍜?/span>tn閮芥槸濂囨暟錛屽垯綰㈣壊綰挎鐨勬暟閲?/span>=钃濊壊綰挎鐨勬暟閲?/span>+1錛岃繖鏍鋒牴鎹瘮渚嬪氨鍙互姹傚嚭綰㈣壊綰挎鐨勯暱搴︿簡銆?br />

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll gcd(ll m,ll n)
{
    if(!n) return m;
    return gcd(n,m%n);
}
int main()
{
    ll m,n,tm,tn,t;
    while(scanf("%lld %lld",&m,&n)!=EOF)
    {
        tm=m>n?m:n;
        tn=m<n?m:n;
        t=gcd(m,n);
        tm/=t;
        tn/=t;
        if(tm%2==0||tn%2==0)
        {
            printf("%.3lf\n",sqrt((double)(tm*tm+tn*tn))/2*t);
            continue;
        }

        double ans;
        ans=sqrt((double)(tm*tm+tn*tn))*(tm*tn+1)/(2*tm*tn)*t;
        printf("%.3lf\n",ans);
    }
    return 0;
}

 



C灝忓姞 2012-02-29 21:03 鍙戣〃璇勮
]]>
zoj 3573 Under Attack 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/02/26/166539.htmlC灝忓姞C灝忓姞Sun, 26 Feb 2012 02:35:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/02/26/166539.htmlhttp://www.shnenglu.com/cxiaojia/comments/166539.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/02/26/166539.html#Feedback1http://www.shnenglu.com/cxiaojia/comments/commentRss/166539.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166539.html

宸у鏁扮粍鎴栬呬竴緇寸嚎孌墊爲銆?br />姣旇禌鏃舵病鏈変粩緇嗙湅棰橈紝緇撴潫鏍囪鍐欓敊浜嗭紝瀵艱嚧TLE浜嗕袱嬈°傚ぇ鑷存剰鎬濇槸錛岀嚎孌墊爲闀垮害[0,len]錛屽垵濮嬪寲涓?/span>0錛屾彃鍏ュ尯闂村閲忥紝鏈鍚庢眰涓や釜鏈澶у肩殑浣嶇疆錛屼竴涓槸浠庡乏鍒板彸鐨勬渶澶у鹼紙閬囧埌鐨勭涓涓渶澶у煎嵆涓烘墍姹傦級錛屼竴涓槸浠庡彸鍒板乏鐨勬渶澶у箋?br />濂介暱鏃墮棿娌″啓綰挎鏍戠殑鍘熷洜錛屽鑷存垜鐩存帴涓婃ā鏉夸簡錛岀粨鏋勪綋鍙橀噺鏈夌偣澶氾紝鍐欑殑涓嶆槸寰堝ソ錛屼唬鐮佸緢闀褲傛寮忔瘮璧涗腑絎竴涓嚎孌墊爲銆?br />鍚庢潵鍚鏈塐錛坣錛夌殑綆楁硶錛岀獊鐒跺氨鎯寵搗鏉ヤ簡瀛︽牎oj涓婃湁涓閬撳閥濡欒繍鐢ㄦ暟緇勭殑棰橈紝鐒跺悗鎰熻鐢ㄦ暟緇勫彲浠ユ悶錛岃瘯浜嗕竴涓婣C鎺変簡錛屾椂闂?900+錛屾瘮綰挎鏍戠殑5000+灝戝浜嗐傘?br />銆?br />鏁扮粍浠g爜錛?br />

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXM=15003;
int a[MAXM];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
   {
       int l,r,b;
       memset(a,0,sizeof(a));
       while(scanf("%d %d %d",&l,&r,&b))
       {
           if(l==-1) break;
           a[l]+=b;
           a[r+1]-=b;
       }
       int lmax=a[0],posl=0;
       for(int i=1;i<=n;i++)
       {
           a[i]+=a[i-1];
           if(lmax<a[i])
           {
               lmax=a[i];
               posl=i;
           }
       }
       int posr;
       for(int i=n;i>=0;i--)
       {
           if(a[i]==lmax)
           {
               posr=i;
               break;
           }
       }
       printf("%d %d\n",posl,posr);
   }


    return 0;
}



綰挎鏍戜唬鐮侊細

#include<iostream>
#include<cstdio>
using namespace std;
inline int L(int r){return r<<1;}
inline int R(int r){return (r<<1)+1;}
inline int MID(int l,int r){return (l+r)>>1;}
const int MAXN=15003;
typedef struct
{
    int left,right;
    int _max,posl,posr;
    int add;
}Node;
Node tree[MAXN*4];
//int arr[MAXN];
void Create(int l,int r,int root)
{
    tree[root].left=l;
    tree[root].right=r;
    if(l==r)
    {
        tree[root]._max=0;
        tree[root].posl=l;
        tree[root].posr=r;
        tree[root].add=0;
        return;
    }
    int mid=MID(l,r);
    Create(l,mid,L(root));
    Create(mid+1,r,R(root));
    tree[root]._max=0;
    tree[root].posl=l;
    tree[root].posr=r;
    tree[root].add=0;
}
void Update_info(int node)
{
    if(tree[node].add)
    {
        tree[L(node)].add+=tree[node].add;//鏇存柊瀛愭爲鏃朵細鐢ㄥ埌
        tree[R(node)].add+=tree[node].add;
        tree[L(node)]._max+=tree[node].add;
        tree[R(node)]._max+=tree[node].add;
        tree[node].add=0;
    }
}


void Updata(int l,int r,int val,int root)
{
    if(l<=tree[root].left&&tree[root].right<=r)
    {
        tree[root].add+=val;
        tree[root]._max+=val;
        return;
    }
    Update_info(root);
    if(tree[root].left==tree[root].right) return;
    int mid=(tree[root].left+tree[root].right)>>1;
    if(l>mid) Updata(l,r,val,(root<<1)+1);
    else if(r<=mid) Updata(l,r,val,root<<1);
    else
    {
        Updata(l,mid,val,root<<1);
        Updata(mid+1,r,val,(root<<1)+1);
    }
    if(tree[L(root)]._max>tree[R(root)]._max)
    {
        tree[root]._max=tree[L(root)]._max;
        tree[root].posl=tree[L(root)].posl;
        tree[root].posr=tree[L(root)].posr;
    }
    else if(tree[L(root)]._max==tree[R(root)]._max)
    {
        tree[root]._max=tree[L(root)]._max;
        tree[root].posl=tree[L(root)].posl;
        tree[root].posr=tree[R(root)].posr;
    }
    else
    {
        tree[root]._max=tree[R(root)]._max;
        tree[root].posl=tree[R(root)].posl;
        tree[root].posr=tree[R(root)].posr;
    }
}




int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int l,r,b;
        Create(0,n,1);
        while(scanf("%d %d %d",&l,&r,&b))
        {
            if(l==-1) break;
            Updata(l,r,b,1);
        }
        printf("%d %d\n",tree[1].posl,tree[1].posr);
    }


    return 0;
}

 



C灝忓姞 2012-02-26 10:35 鍙戣〃璇勮
]]>
Ural 1119. Metro NYOJ 195 椋炵繑 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/02/25/166466.htmlC灝忓姞C灝忓姞Sat, 25 Feb 2012 00:50:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/02/25/166466.htmlhttp://www.shnenglu.com/cxiaojia/comments/166466.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/02/25/166466.html#Feedback1http://www.shnenglu.com/cxiaojia/comments/commentRss/166466.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166466.html

DP銆?/span>

錛戙?span style="font-family: 瀹嬩綋;">姣忎竴琛屾渶澶氬彧鍙互璧頒竴嬈℃嵎寰勶紝姣忎竴鍒椾篃鏄渶澶氬彧鍙互璧頒竴嬈℃嵎寰?/span>

錛掋?span style="font-family: 瀹嬩綋;">姣忔璧拌繃鎹峰緞鍚庣殑妯潗鏍囧拰綰靛潗鏍囬兘瑕佸ぇ浜庝箣鍓嶇殑鍧愭爣

鍙姹傚嚭浠庤搗鐐瑰埌緇堢偣鎵緇忚繃鐨勬渶澶氱殑鎹峰緞錛屽氨鑳藉緱鍒版渶灝戠殑璺▼銆傛瘡涓姝ョ殑鏈浼樿В鐢ㄤ箣鍓嶈蛋榪囩殑璺緞鎵姹傦紝婊¤凍鏃犲悗鏁堟э紝姣忎竴涓瓙鐘舵侀兘鍙互姹傚嚭鏈浼樿В錛屾弧瓚蟲渶浼樺瓙緇撴瀯錛屽彲浠ョ敤dp瑙e喅銆?/span>

f[i]=max(f[j]+1,f[i]);

褰?/span>j鐐瑰潗鏍囧皬浜庣偣錛?/span>i鐐逛負鎹峰緞鏃訛紝璧板埌i鐐瑰潗鏍囨椂緇忚繃鐨勬渶澶氭嵎寰勬暟=max(璧板埌j鐐圭殑鏈澶氭嵎寰勬暟+1錛岃蛋鍒?/span>i鐐規椂鐨勬渶澶氭嵎寰勬暟)

鏈鍚庢壘鍑烘渶澶х殑f(i)灝辨槸鑳界粡榪囨渶澶氱殑鎹峰緞

娉ㄦ剰鍧愭爣鐨勮緭鍏ユ病鏈夐『搴忔э紝瑕佽繘琛屾帓鍒椼?br />

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
const int MAXN=1003;
typedef struct
{
    int a,b;
}point;
point p[MAXN];
int f[1003];
bool cmp(point p1,point p2)
{
    if(p1.a==p2.a) return p1.b<p2.b;
    return p1.a<p2.a;
}
int main()
{
    //freopen("1.in","r",stdin);
    int m,n;
    while(cin>>n>>m)
    {
        int k;
        cin>>k;
        for(int i=0;i<k;i++)
        {
            cin>>p[i].a>>p[i].b;
            f[i]=1;
        }
        sort(p,p+k,cmp);//濡傛灉妯潗鏍囩浉絳夛紝鎸夌収綰靛潗鏍囦粠灝忓埌澶ф帓搴忥紝鍚﹀垯鎸夌収妯潗鏍囦粠灝忓埌澶ф帓搴?/span>
        int v=0,flag=0;
        
        //dp
        for(int i=0;i<k;i++)
        {
            for(int j=0;j<=i;j++)
            {
                if(p[i].a>p[j].a)
                {
                    if(p[i].b>p[j].b) f[i]=max(f[j]+1,f[i]);
                }
            }

        }
        //姹傜敤鍒版渶澶氭嵎寰勭殑鐐?/span>
        int ma=*max_element(f,f+k);
        cout<<(int)((m+n-2*ma)*100+ma*100*sqrt(2.0)+0.5)<<endl;

    }


    return 0;
}
        



C灝忓姞 2012-02-25 08:50 鍙戣〃璇勮
]]>
Ural 1146. Maximum Sum NYOJ 104 鏈澶у拰 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/02/24/ural1146.htmlC灝忓姞C灝忓姞Fri, 24 Feb 2012 08:58:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/02/24/ural1146.htmlhttp://www.shnenglu.com/cxiaojia/comments/166439.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/02/24/ural1146.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/166439.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/166439.html

a[i][j]=a[i-1][j]+among;榪欐牱瀛樺肩殑璇濆氨鍙互杞寲鎴愭眰 鍜屾渶澶ц繛緇瓙涓?br />

0.031

156 KB





#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int INF=0x7fffffff-1;
int a[103][103];
int main()
{
    memset(a,0,sizeof(a));
    int n,among;
    while(scanf("%d",&n)!=EOF)
    {
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            scanf("%d",&among);
            a[i][j]=a[i-1][j]+among;
        }
    int ans=-INF;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int maxnum=a[j][1]-a[i][1];
            ans=max(maxnum,ans);
            for(int k=2;k<=n;k++)
            {
                if(a[j][k]-a[i][k]+maxnum<a[j][k]-a[i][k])
                {
                    maxnum=a[j][k]-a[i][k];
                    ans=max(maxnum,ans);
                }
                else
                {
                    maxnum+=a[j][k]-a[i][k];
                    ans=max(maxnum,ans);
                }
            }

        }
    }
    printf("%d\n",ans);
    }


    return 0;
}

 



C灝忓姞 2012-02-24 16:58 鍙戣〃璇勮
]]>
NYOJ 136 絳夊紡 瑙i鎶ュ憡http://www.shnenglu.com/cxiaojia/archive/2012/01/30/nyoj136.htmlC灝忓姞C灝忓姞Sun, 29 Jan 2012 17:40:00 GMThttp://www.shnenglu.com/cxiaojia/archive/2012/01/30/nyoj136.htmlhttp://www.shnenglu.com/cxiaojia/comments/164665.htmlhttp://www.shnenglu.com/cxiaojia/archive/2012/01/30/nyoj136.html#Feedback0http://www.shnenglu.com/cxiaojia/comments/commentRss/164665.htmlhttp://www.shnenglu.com/cxiaojia/services/trackbacks/164665.htmla1*x13+a2*x23鐨勬墍鏈夋儏鍐靛瓨鍌ㄥ湪鍝堝笇琛ㄤ腑錛岀劧鍚庣敤a3*x33+a4*x43+a5*x53鍘昏〃涓煡鎵懼拰涓?鐨勬儏鍐點傜敤鏁扮粍鏆村姏鐨勮瘽浼氳秴鍐呭瓨銆?sup style="color: #464646; font-family: Tahoma, Arial, sans-serif, simsun; background-color: #ffffff; ">
榪欎釜棰樺緢涔呬互鍓嶅仛榪囷紝铏界劧AC浜嗕絾鏄敊鐨勩備箣鍓嶅仛鐨勬椂鍊欒寰楁湁涓緇勬暟鎹秴int浜嗭紙鑰佹槸RE錛夛紝鑰屼笖褰撴椂璁や負鍙湁榪欎竴緇勬暟鎹秴浜嗭紝鎵浠ュ綋鏃跺氨鎶婅繖緇勬暟鎹繘琛岀壒孌婂寲澶勭悊浜嗐傚悗鏉ュ皬鐗涙壘鍑轟簡闂鎴戞墠鎰忚瘑鍒版牴鏈病鏈夎秴鍑篿nt錛屾垜鍘繪帀鐗規畩鍖栧鐞嗗悗鎻愪氦TLE錛屼笉鏄疪E錛屾垜寮濮嬬籂緇撳綋鏃跺埌搴曟槸鎬庝箞鍋氱殑銆?br />鎴戦噸鏂版鏌ヤ簡涓閬嶄唬鐮侊紝鍙戠幇鎴戠殑鍝堝笇綆楁硶鍔犱笂閭g粍鐗規畩鏁版嵁錛屾椂闂村鏉傚害O錛坣*m錛夛紝n杈懼埌100涓囷紝m杈懼埌1涓囥傝繖鏃墮棿浼や笉璧峰晩銆傚悗鏉ユ兂鎯沖搱甯岃繕鍙互浼樺寲錛屼簬鏄垜灝辨敼浜嗕竴涓嬪搱甯岀畻娉曪紝澶嶆潅搴﹂檷浣庡埌浜哋錛坣錛夛紝鏈緇堜篃欏哄埄AC銆?br />
 
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
const int MAX=100003;
const int MAXSUM=12500000;
int a[1003];

void g()
{
    for(int i=-50;i<=50;i++)
    {
        a[i+50]=i*i*i;
    }
}


template <class T>
class hash
{
private:

    int pos;
    int next[MAX];
    int head[MAX];
    int key[MAX];
    int cnt[MAX];
public:
    int count;
    void search(const int x);
    bool search1(const int x);
    void push(const int x);
    void clear();

};

template <class T>
inline bool hash<T>::search1(const int x)
{
    int temp=abs(x)%MAX;
    int t=head[temp];
    while(t!=-1)
    {
        if (x==key[t])
        {
            cnt[t]++;
            return true;
        }
        t=next[t];
    }
    return false;
}

template <class T>
inline void hash<T>::search(const int x)
{
    int temp=abs(x)%MAX;
    int t=head[temp];
    while(t!=-1)
    {
        if (x==-key[t])
        {
            count+=cnt[t];
        }
        t=next[t];
    }
}
template <class T>
inline void hash<T>::push(const int x)
{
    if(search1(x)) return;
    int temp=abs(x)%MAX;

    if (head[temp]!=-1)
    {
        next[pos]=head[temp];
    }
    head[temp]=pos;
    key[pos]=x;
    cnt[pos]=1;
    pos++;
}
template <class T>
void hash<T>::clear()
{
    count=0;
    pos=0;
    memset(next,-1,sizeof(next));
    memset(head,-1,sizeof(head));
    memset(cnt,0,sizeof(cnt));
}
hash<int> h;

int main()
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    memset(a,0,sizeof(0));
    g();
    while(T--)
    {

        h.clear();
        int a1,a2,a3,a4,a5;
        int i,j,k;
        int n;
        scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
        for(i=-50;i<=50;i++)
        {

            for(j=-50;i!=0&&j<=50;j++)
            {
                if(j==0) continue;
                n=a1*a[i+50]+a2*a[j+50];
                h.push(n);

            }
        }
        for(i=-50;i<=50;i++)
        {

            for(j=-50;i!=0&&j<=50;j++)
            {
                for(k=-50;j!=0&&k<=50;k++)
                {
                    if(k==0) continue;
                    n=a3*a[i+50]+a4*a[j+50]+a5*a[k+50];
                    if(n > MAXSUM || n < -MAXSUM)
                        continue;
                    h.search(n);
                }
            }
        }

        printf("%d\n",h.count);
    }

    return 0;
}
        


C灝忓姞 2012-01-30 01:40 鍙戣〃璇勮
]]>
久久久婷婷五月亚洲97号色 | 亚洲AV无码1区2区久久| 久久99精品国产麻豆蜜芽| 99久久国产热无码精品免费| 欧美日韩久久中文字幕| 久久人人爽人人澡人人高潮AV| 亚洲一区中文字幕久久| 国产91色综合久久免费| a高清免费毛片久久| 国产韩国精品一区二区三区久久| 无遮挡粉嫩小泬久久久久久久| 99久久免费国产精品特黄| 久久久久久伊人高潮影院| 中文字幕热久久久久久久| 精品国产乱码久久久久久呢| 亚洲国产欧美国产综合久久| 亚洲av日韩精品久久久久久a| 久久午夜无码鲁丝片| 国产成年无码久久久久毛片| 国产精品久久自在自线观看| 欧美久久精品一级c片片| 国产精品欧美久久久久天天影视 | 久久久久国产精品麻豆AR影院| 岛国搬运www久久| 久久青青草原精品国产不卡| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 久久精品国产99久久久香蕉 | 婷婷久久综合| 久久精品国产AV一区二区三区| 久久综合给久久狠狠97色| 久久99国产精品久久久| 久久久久久久久久免免费精品| 亚洲午夜无码久久久久小说| 久久亚洲私人国产精品| 国产精品gz久久久| 久久久精品国产免大香伊| 精品综合久久久久久888蜜芽| 国产精品久久久久乳精品爆| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 久久777国产线看观看精品| 久久99精品久久久久久秒播|