锘??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕成人精品久久不卡 ,久久精品国产亚洲AV无码娇色,9久久9久久精品http://www.shnenglu.com/luyulaile/archive/2009/07/25/91180.htmlluisluisSat, 25 Jul 2009 14:36:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/25/91180.htmlhttp://www.shnenglu.com/luyulaile/comments/91180.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/25/91180.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/91180.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/91180.html絎竴嬈?.3縐掞紝絎簩嬈?.1絎笁嬈★紝0.0縐?/pre>
#include<stdio.h>
void func(int i)
{
int m,n,k,j;
int temp,vmax=4*i+2;
for(m=1;m<i;m++)
for(n=m;n<=i;n++)
{
j=m*n;//閬垮厤浜嗕笁閲嶅驚鐜?/span>
if(j>i)
break;//鑳界渷涓嶅皯鏃墮棿
if(i%j==0)//鍒ゆ柇鏄惁鑳芥暣闄?/span>
{
k=i/j;
temp=2*(k*m+k*n+j);
if(temp<vmax)
vmax=temp;
}
}
printf("%d\n",vmax);
}
int main()
{
int num,n;
scanf("%d",&num);
getchar();
while(num--)
{
scanf("%d",&n);
getchar();
func(n);
}
//system("PAUSE");
return   0;
}


luis 2009-07-25 22:36 鍙戣〃璇勮
]]>
joj 1894 楂樼簿搴﹂櫎娉曟湁宸цВhttp://www.shnenglu.com/luyulaile/archive/2009/07/18/90440.htmlluisluisSat, 18 Jul 2009 09:38:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/18/90440.htmlhttp://www.shnenglu.com/luyulaile/comments/90440.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/18/90440.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/90440.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/90440.htmlGiven any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?

Sample input

3
7
9901

Output for sample input

3
6
12


鍙互涓嶇敤楂樼簿搴﹂櫎娉曪紝鐩存帴濡備笅錛屽緢宸у錛屼笉閫氱敤銆?br>

#include <stdio.h>
int main()
{
int n, a, b;
while (EOF != scanf("%d", &n))
{
a = 1;
b = 1;
while (a)
{
a = (a * 10 + 1) % n;
++b;
}
printf("%d\n", b);
}
}

楂樼簿搴﹂櫎娉?br>----
#include<iostream>
#include<cstdlib>
using namespace std;
int a[9]={1,11,111,1111,11111,111111,1111111,11111111,111111111};
const int MOD=11111;
  bool test(int i,int j)
  {
  if(j<10)
  {
   if(a[j-1]%i==0)
   return true;
   return false;
  }
  else
  {
   int temp=0;
   int k=j%5;
   int p=j/5;
   if(k==0)
   {
    for(int m=1;m<=p;m++)
       {
     temp*=100000;
        temp+=MOD;
        temp%=i;
       
       }
       if(temp==0)
       return true;
       else
       return false;
     }
     else
     {
    int m,f=1;
    for(m=1;m<=p;m++)
       {
        temp*=100000;//鐢變簬5浣?浣嶉櫎錛屽簲褰撲箻涓?0^5;
     temp+=MOD;
        temp%=i;
       
       }
       for(m=0;m<k;m++)//鏈鍚庡簲褰撲箻浠ュ叾鍚庣殑浣嶆暟涔?0^n錛?br>       f*=10;
     if((temp*f+a[k-1])%i==0)
     return true;
     else
     return false;
     }
   
  }
  }
  int main()
  {
  //freopen("s.txt","r",stdin);
  //freopen("key.txt","w",stdout);
  int i;
  while(cin>>i)
  {
  if(i==1)
  {
   cout<<'1'<<endl;
   continue;
  }
  for(int j=2;;j++)
  {
   if(test(i,j))
   {
    cout<<j<<endl;
    break;
   }
      }
  }

  //system("PAUSE");
  return   0;
  }



luis 2009-07-18 17:38 鍙戣〃璇勮
]]>
joj 2391 words 娣辨悳鍓灊http://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.htmlluisluisSun, 05 Jul 2009 04:33:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.htmlhttp://www.shnenglu.com/luyulaile/comments/89274.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/05/89274.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89274.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89274.html Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE stdin/stdout 3s 8192K 439 74 Standard

Io and Ao are playing a word game. They say a word in the dictionary by turns. The word in the dictionary only contains lowercase letters. And the end character of the former said word should be the same as the start character of the current said word. They can start the game from any word in the dictionary. Any word shouldn't be said twice. Now, we define the complexity of the game that is the sum length of all words said in the game. Give you a dictionary, can you tell me the max complexity of this word game?

Input

The first line contains a single positive integer n(0 < n <=12). Next n lines are n words in the dictionary. The length of each word will not exceed 100.

Output

A single integer represents the complexity of the game.

Sample Input

3
joj
jlu
acm
6
cctv
redcode
lindong
we
love
programming
3
daoyuanlee
come
on

Sample Output

6
11
10

Problem Source: provided by loon

#include<iostream>
#include<cstdlib>
using namespace std;
struct S
{
 string a;
 char begin;
 char end;
 int length;
 }s[13];
 int visited[13];
int temp; 
void search(int a,int num,int pre)
 {
  
  for(int i=0;i<num;i++ )
  {
   if(s[i].begin==s[pre].end&&visited[i]==0)
   {
    visited[i]=1;
    search(a+s[i].length,num,i);
    if(a+s[i].length>temp)temp=a+s[i].length;
    visited[i]=0;
   }
  }
 }
  int main()
  {
  freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
   int num;
   while(cin>>num)
   {
    int i;
  temp=0;
  for( i=0;i<num;i++)
  {
   cin>>s[i].a;
   s[i].length=(s[i].a).size();
   s[i].begin=(s[i].a)[0];
   s[i].end=(s[i].a)[s[i].length-1];
   if(s[i].length>temp)
   temp=s[i].length;
     }
  for(i=0;i<num;i++) 
     {
   memset(visited,0,sizeof(visited));
   visited[i]=1;
   search(s[i].length,num,i);
  }
  cout<<temp<<endl;
 }

  //system("PAUSE");
  return   0;
  }

浠ヤ笂浠g爜瓚呮椂銆傚畬鍏ㄥ彲浠ュ壀鏋濄?br>涓句釜渚嬪瓙
abc
cbd
dbm
dbacmdp
鎴戠殑紼嬪簭涓鐩存悳鍟婃悳錛屾瘡嬈℃悳瀹岄兘閲嶆柊寮濮嬨傛瘮濡傚湪浠寮澶村悗錛屾悳鍒癱錛屼笅嬈″啀鎼滅儲鏃剁洿鎺ュ埄鐢╟鐨勭粨鏋滐紝榪欐槸娣辨悳鐨勭壒鐐瑰喅瀹氱殑錛侊紒錛?br>*************************
榪欑綾諱技鐨勬湁搴忔悳绱㈤兘鍙互鐢?nbsp;    *  澶囧繕褰曟柟娉?
**************************
#include<iostream>
#include<cstdlib>
using namespace std;
int num;
struct S
{
 string a;
 char begin;
 char end;
 int length;
 }s[13];
 int visited[13];
int temp;
int sum[13]; 
int search(int pre)//·µ»Ø´ÓpreµãÒÔºóµÄ×ܵÄÖµ
 {
  int j=s[pre].length,k=0;
  for(int i=0;i<num;i++ )
  {
   if(s[i].begin==s[pre].end&&visited[i]==0&&i!=pre)//蹇呴』瑕佹湁I錛?pre
   {
    visited[i]=1;
    k=search(i)+s[pre].length;
    if(k>j)j=k;
   }
   else
   {
    if(s[i].begin==s[pre].end&&i!=pre)//蹇呴』瑕佹湁i!=pre
    return sum[i]+s[pre].length;//鐩稿綋浜庡蹇樺綍錛岃屼笖鏃犻渶visited[i]=0;
   }
  }
  sum[pre]=j;
  return j;
 }
  int main()
  {
 freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
   while(cin>>num)
   {
    int i,j;
  temp=0;
  j=0;
  for( i=0;i<num;i++)
  {
   cin>>s[i].a;
   s[i].length=(s[i].a).size();
   s[i].begin=(s[i].a)[0];
   s[i].end=(s[i].a)[s[i].length-1];
   if(s[i].length>temp)
   temp=s[i].length;
     }
  for(i=0;i<num;i++) 
     {
   memset(visited,0,sizeof(visited));
            memset(sum,0,sizeof(sum));
   visited[i]=1;
   j=search(i);
   if(j>temp)
   temp=j;
  }
  cout<<temp<<endl;
 }

  //system("PAUSE");
  return   0;
  }

鍥犱負I錛?pre鍙堥敊浜嗗嚑涓嬨?br>浠ュ悗debug灝介噺鑷繁鐢ㄧ溂鐫涚湅錛屾洿鐪佹椂闂達紒錛侊紒錛侊紒錛侊紒錛侊紒



luis 2009-07-05 12:33 鍙戣〃璇勮
]]>
joj 1995: Energy 姹傝繛緇瓙涓蹭嬌鍜屾渶澶?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 04 Jul 2009 01:27:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89209.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89209.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89209.html</trackback:ping><description><![CDATA[<p>Energy</p> <hr> <p> <table cellSpacing=3 cellPadding=3 width="75%" border=1> <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7> <tbody> <tr> <th height=40>Status</th> <th>In/Out</th> <th>TIME Limit</th> <th>MEMORY Limit</th> <th>Submit Times</th> <th>Solved Users</th> <th>JUDGE TYPE</th> </tr> <tr> <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td> <td>stdin/stdout</td> <td>3s</td> <td>10240K</td> <td>717</td> <td>196</td> <td>Standard</td> </tr> </tbody> </table> </p> <div id="j53r5xt" class=prob_text> <p>Mr. Jojer is a very famous chemist. He is doing a research about behavior of a group of atoms. Atoms may have different energy and energy can be positive or negative or zero, e.g. 18 or -9. Absolute value of energy can not be more than 100. Any number of continuous atoms can form an atom-group. Energy of an atom-group is defined by the sum of energy of all the atoms in the group. All the atoms form an atom-community which is a line formed by all the atoms one by one. Energy of an atom-community is defined by the greatest energy of an atom-group that can be formed by atoms in the atom-community. The problem is, given an atom-community, to calculate its energy.</p> <h3>Input</h3> <p>The input contains several test cases. Each test case consists of two lines describing an atom-community. The first line of each test case contains an integer N(N<=1000000), the number of atoms in the atom-community. The second line of each test case contains N integers, separated by spaces, each representing energy of an atom, given in the order according to the atom-community. The last test case marks by N=-1, which you should not proceed.</p> <h3>Output</h3> <p>For each test case(atom-community description), print a single line containing the energy.</p> <h3>Sample Input</h3> <pre>5 8 0 6 4 -1 -1</pre> <h3>Sample Output</h3> <pre>18</pre> </div> <p><br>鐞嗚В棰樻剰寰堥噸瑕侊紝棰樼洰鐨勬剰鎬濇槸璇?鍦╩涓腑閫?nbsp;  榪炵畫鐨刵涓猘tom鑳介噺鍊?浣垮叾鏈澶с?br>紼嬪簭涓璼umtemp錛宻um銆俿umtemp紜畾鐨勬槸鍏跺乏杈圭晫錛宻um紜畾鍏跺彸杈圭晫銆?br>sumtemp紜畾宸﹁竟鍓峮涓暟涔嬪拰涓鴻礋鐨勬渶澶х殑n錛屼笖絎琻涓暟鏄劇劧涓鴻礋錛岀劧鍚庝粠n+1寮濮嬮夋暟銆?br>sum紜畾浜嗗彸杈圭晫浣垮叾鏈澶с?br>姹傚拰鏈澶ч兘鍙互鐢ㄨ繖縐嶆濊礬錛侊紒錛侊紒錛侊紒錛侊紒錛侊紒<br>涓句緥<br>1錛?錛?4錛?錛?錛?2錛?錛?錛?6錛?錛?3錛?錛?0<br>璇風湅sumt1=1,sum=1<br>sumt2=2;sum=1+2=3;<br>sum3=sum2-4=-1;鍒檚umtemp=0;sum涓嶅彉銆?br>sum4=sumtemp+4;sum<sum4,sum=4;<br>sum5=sumtemp+2錛泂um<sum5,sum=6<br>鎬諱箣sum鍙湁鍦╯um<sumtemp鏃舵墠淇敼銆俿umtemp<0鍒欐竻0.<br>涓緇磀p.<br>#include"stdio.h"<br>int main()<br>{<br> freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br> int n;<br> int a;<br> while(scanf("%ld",&n),n!=-1)<br> {  <br>      long long  sum=-0x7fffffff,sumtemp=-0x7fffffff;<br>   for(long i=0;i<n;i++)<br>   { <br>    scanf("%d",&a);<br>    if(sumtemp>0)<br>   sumtemp+=a;<br>    else<br>   sumtemp=a;<br>    if(sumtemp>sum)<br>   sum=sumtemp;</p> <p>   }<br>   printf("%lld\n",sum);</p> <p> }<br> return 0;<br>}</p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-04 09:27 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 1867 squares 娣辨悳鐙傚壀鏋濓紝鐙傝秴鏃?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 03 Jul 2009 15:29:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89196.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89196.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89196.html</trackback:ping><description><![CDATA[<p>閿欒浠g爜錛岃繃涓嶄簡鐨勬暟鎹?4錛?5 10 17 16 12 1 10 20 17 19 4 5 9 5  鍙兘瑙o細(20 15 5 ),(19 17 4 ),( 17 12 10 1 ), ( 16 10 9 5 )<br>涓嬮潰鐨勪唬鐮?#8220;no”錛屽洜涓?20 19 1),(17鎺ヤ笅鏉ュ噾涓嶅嚭鏉?nbsp;)<br>#include<iostream><br>#include<cstdlib><br>#include<algorithm><br>using namespace std;<br> int length[21];<br> int mark[21];<br> bool cmp(int x,int y)<br>{<br>    return x>y; <br>}</p> <p><br>  int  dfs(int sum,int flag,int n,int time)//´Ótime¿ªÊ¼ËÑË÷ <br>  {<br>  if(sum==0)return 1;<br>    if(time<n) <br>  {<br>   for(int k=time;k<n;k++)<br>   {<br>    if(mark[k]<0&&sum-length[k]>=0)<br>    {<br>     mark[k]=flag;<br>     if(dfs(sum-length[k],flag,n,k+1))<br>     return 1;<br>     else<br>     mark[k]=-1;<br>       } <br>   }<br>  }<br>     <br> return 0;<br>  }<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num,n;<br> <br>  cin>>num;<br>  while(num--)<br>  {<br>  int sum=0;<br>  cin>>n;<br>  for(int k=0;k<n;k++)<br>  {<br>   cin>>length[k];<br>   mark[k]=-1;<br>   sum+=length[k];<br>  }<br>  sort(length,length+n,cmp);<br>  if(sum%4!=0||length[0]>sum/4)<br>  cout<<"no"<<endl;<br>  else<br>  {<br>   sum/=4;<br>   if(dfs(sum,1,n,0))<br>    {<br>   if(dfs(sum,2,n,0))<br>          {<br>     if(dfs(sum,3,n,0))<br>     cout<<"yes"<<endl;<br>     else<br>     cout<<"no"<<endl;<br>        } <br>        else<br>        cout<<"no"<<endl;<br>          }<br>         else<br>         cout<<"no"<<endl;<br>  }<br>    }<br>  //system("PAUSE");<br>  return   0;<br>  }<br>姝g‘鐨勮В娉曞簲褰撴槸錛屽湪涓璧鋒悳绱€?br>涓嬮潰鏄竴孌佃秴鏃剁殑浠g爜<br>#include<iostream><br>#include<cstdlib><br>#include<algorithm><br>using namespace std;<br> int length[21];<br> int mark[21];<br> int flag=0;<br> int target;<br> bool cmp(int x,int y)<br>{<br>    return x>y; <br>}</p> <p>  int func(int i)<br>  {<br>  while(mark[i]>0)<br>  i++;<br>  return i;<br> }<br>  void  dfs(int sum,int n,int time,int level)//浠庡簭鍙蜂負time鐨勫紑濮嬫悳绱?<br>  {<br>  if(flag)return ;<br>  if(sum==0&&level==3)<br>  {<br>  flag=1;<br>  return;<br>     }<br>     if(sum==0)<br>     {<br>   level++;<br>   dfs(target,n,func(0),level);<br>  }<br>    else if(time<n) <br>  {<br>   for(int k=time;k<n;k++)<br>   {<br>    if(k>1)<br>               {<br>                <br>                if(length[k]==length[k-1]&&!mark[k-1])<br>                    continue;//鏄劇劧 <br>               }<br>                if(sum<length[n-1])  continue;//鏄劇劧 <br>    if(mark[k]<0&&sum-length[k]>=0)<br>    {<br>     mark[k]=1;<br>     dfs(sum-length[k],n,func(k+1),level);<br>     mark[k]=-1;<br>       } <br>   }<br>  }<br>  }<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num,n;<br> <br>  cin>>num;<br>  while(num--)<br>  {<br>  int sum=0;<br>  cin>>n;<br>  for(int k=0;k<n;k++)<br>  {<br>   cin>>length[k];<br>   mark[k]=-1;<br>   sum+=length[k];<br>  }<br>  sort(length,length+n,cmp);<br>  if(sum%4!=0||length[0]>sum/4)<br>  cout<<"no"<<endl;<br>  else<br>  {<br>   sum/=4;<br>   target=sum;<br>   dfs(sum,n,0,0);<br>       if(flag==0)<br>       cout<<"no"<<endl;<br>       else<br>       cout<<"yes"<<endl;<br>  }    <br>    }<br>  //system("PAUSE");<br>  return   0;<br>  }<br></p> <p>涓婇潰瓚呮椂灝辮秴鏃跺師鍥犳槸鍑忔灊涓嶅交搴曘俵evel鏍囪涔熶笉澶ソ<br>鍐沖畾鍙﹀鐐夌伓,鍏堢湅鐪嬪埆浜虹殑浠g爜<br>#include<iostream><br>#include<algorithm><br>using namespace std;<br>int s[21];<br>int v[21];<br>int len;<br>int m;<br>int dfs(int cur,int num,int beg,int fin)<br>{     <br> int solve(int );<br> if(num==1)<br>  return 1;<br> if(cur==len)<br> {<br>  return solve(num-1);<br> }<br>   for(int i=beg;i>=fin;i--)<br>   {<br>    if(!v[i]&&cur+s[i]<=len)<br>    {   <br>     v[i]=1;<br>     if(dfs(cur+s[i],num,i-1,fin))<br>      return 1;<br>     v[i]=0;<br>    }<br>   }<br>   return 0;<br>}</p> <p>int solve(int edge_num)<br>{    <br>     int i;<br>  for(i=m;i>=1;i--)<br>   if(!v[i])<br>   {  <br>    v[i]=1;<br>    if(dfs( s[i],edge_num,i-1,1))<br>     return 1;<br>    v[i]=0;<br>   }<br> return 0;<br>}</p> <p>int main()<br>{<br> int n;<br> cin>>n;<br> while(n--)<br> {<br>  <br>  cin>>m;<br>  int i;<br>  int sum=0;<br>  for(i=1;i<=m;i++)<br>  {<br>   cin>>s[i];<br>   sum+=s[i];<br>   v[i]=0;<br>  }<br>  <br>  len=sum/4;<br>  if(4*len!=sum)<br>  {<br>   cout<<"no"<<endl;<br>   continue;<br>  }<br>  sort(s+1,s+m+1);<br>  if(s[m]>len)<br>  {<br>   cout<<"no"<<endl;<br>   continue;<br>  }<br>  if(solve(4))<br>   cout<<"yes"<<endl;<br>  else<br>   cout<<"no"<<endl;<br> }<br> return 0;<br>}//鍓灊榪樺彲浠ュ仛寰楁洿濂斤紒錛侊紒<br>浜哄鐨剆olve鍐欏緱濂斤紒錛侊紝緇撳悎dfs.</p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89196.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-03 23:29 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/03/89196.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>搴忓伓瀵圭敓鎴愭硶涓縐嶈〃鐜板艦寮?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 02 Jul 2009 08:05:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89086.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89086.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89086.html</trackback:ping><description><![CDATA[<p>Tug of War</p> <hr> <p> <table cellSpacing=3 cellPadding=3 width="75%" border=1> <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7> <tbody> <tr> <th height=40>Status</th> <th>In/Out</th> <th>TIME Limit</th> <th>MEMORY Limit</th> <th>Submit Times</th> <th>Solved Users</th> <th>JUDGE TYPE</th> </tr> <tr> <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td> <td>stdin/stdout</td> <td>15s</td> <td>8192K</td> <td>479</td> <td>114</td> <td>Standard</td> </tr> </tbody> </table> </p> <div id="l3555bz" class=prob_text>A tug of war is to be arranged at the local office picnic. For the tug of war, the picnickers must be divided into two teams. Each person must be on one team or the other; the number of people on the two teams must not differ by more than 1; the total weight of the people on each team should be as nearly equal as possible. <p>The first line of input contains <em>n</em> the number of people at the picnic. <em>n</em> lines follow. The first line gives the weight of person 1; the second the weight of person 2; and so on. Each weight is an integer between 1 and 450. There are at most 100 people at the picnic. <p>The input may contain several test cases. <p>Your output will be a single line containing 2 numbers: the total weight of the people on one team, and the total weight of the people on the other team. If these numbers differ, give the lesser first. <h3>Sample Input</h3> <pre>3 100 90 200 </pre> <h3>Output for Sample Input</h3> <pre>190 200 </pre> </div> <p><br>鍒╃敤dp鎬濇兂 錛宯涓哄伓鏁版椂姹傚嚭s(n,n/2)錛宯涓哄鏁版椂 涔熸槸s(2n,n/2)錛屽拰sum/2鏈鎺ヨ繎鐨勯偅涓傞潪甯哥粡鍏哥殑鎬濊礬銆?br>S(k, 1) = {A[i] | 1<= i <= k}<br>S(k, k) = {A[1]+A[2]+…+A[k]}<br>S(k, i) = S(k-1, i) U {A[k] + x | x灞炰簬S(k-1, i-1) }<br>//涓涓嬩唬鐮佸彧鑳界敤浜巗um鐗瑰埆灝忕殑鎯呭喌錛屽惁鍒欎細瓚呮椂錛侊紒錛侊紒錛侊紒錛侊紒錛侊紒錛?br>#include<iostream><br>#include<cstdlib><br>#define MAX 101 <br>#define min(a,b) ((a)<(b) ? (a) : (b))<br>using namespace std;</p> <p>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num;<br>  int a[MAX],i,j,k,l,m,NUM;<br>  bool s[MAX][2500];<br>  while(cin>>num)<br>  {<br>  int sum=0;<br>    for(i=1;i<=num;i++)<br>   {<br>  cin>>a[i];<br>  sum+=a[i]; <br>   }<br>   if(num%2==0)NUM=num/2;<br>   else NUM=num/2+1;</p> <p>    for(i=0;i<=num;i++)<br>     for(j=0;j<=sum/2;j++)<br>      s[i][j]=false;//琛ㄧず鍙杋涓墿鍝佽兘鍚﹁揪鍒伴噸閲忔槸j. <br>      <br>   s[0][0]=true;<br>   for(k=1;k<=num;k++)//蹇呴』鍦ㄦ渶澶栧眰錛屽厓绱犱笉鑳介噸澶?<br>   for(j=min(k,NUM);j>=1; j--)//閫掑噺鐨勭粨鏋滄槸浣垮緱涓嶄細鍑虹幇鍦ㄥ悓涓灞傛鐨勪簰涓哄洜鏋?銆併併併併併併併併併併佸閥濡欑殑瀹炵幇浜嗚鏈笂鐨勫簭鍋跺鐢熸垚娉曘?br>   for(i=a[k];i<=sum/2;i++)<br>   {<br>  if(s[j-1][i-a[k]])<br>  s[j][i]=true;<br> }<br> <br> for(i=sum/2; i>=0; i--) {   <br>    if(s[NUM][i]) {   <br>        cout <<i<<" "<<sum-i<<endl;   <br>        break;   <br>    }   <br>}  </p> <p>  }<br>  //system("PAUSE");<br>  return   0;<br>  }<br>涓嬩竴嬈″疄鐜頒竴涓簭鍋剁敓鎴愭硶銆?/p> <p>#include <iostream><br>#include <functional><br>using namespace std;</p> <p>int a[101];<br>bool b[101][45002];</p> <p>int main(){<br>// freopen("s.txt","r",stdin);<br>//  freopen("key.txt","w",stdout);<br>    int N,M,i,j,k;<br>    while(scanf("%d",&N)!=EOF){<br>         memset(b,0,sizeof(b));<br>         a[0]=M=0;<br>        for(i=1;i<=N;i++){<br>             scanf("%d",a+i);<br>             M+=a[i];<br>         }<br>         b[0][0]=1;<br>        for(k=1;k<=N;k++){<br>            for(i=1;i<=N/2;i++){<br>                for(j=M/2;j>=0;j--){<br>                    if(b[i-1][j]){<br>                         b[i][j+a[k]]=1;<br>                     }<br>                 }<br>             }<br>         }<br>        for(i=M/2,j=M/2+1;i>=0;i--,j++){<br>            if(b[N/2][i]){<br>                 printf("%d %d\n",i,M-i);<br>                break;<br>             }<br>            if(b[N/2][j]){<br>                 printf("%d %d\n",M-j,j);<br>                break;<br>             }<br>         }<br>     }<br>    return 0;<br>}<br></p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-02 16:05 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 2250 my friends娣卞害浼樺厛鎼滅儲璁茶Вhttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.htmlluisluisMon, 29 Jun 2009 08:13:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.htmlhttp://www.shnenglu.com/luyulaile/comments/88782.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/06/29/88782.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/88782.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/88782.htmlInput The input consists of a number of cases. The first line on each case contains a positive number n (1 < n <= 100) that specifies the number of points in the graph. A value of n = 0 indicates the end of the input. After this, a second number s is provided, indicating the starting point in my journey (1 <= s <= n). Then, you are given a list of pairs of places p and q, one pair per line. The pair "p q" indicates that I can visit q after p. A pair of zeros ("0 0") indicates the end of the case. As mentioned before, you can assume that the graphs provided will not be cyclic.

Output

For each test case you have to find the length of the longest path that begins at the starting place. You also have to print the number of the final place of such longest path. If there are several paths of maximum length, print the final place with smallest number.

Print a new line after each test case.

Sample Input

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

Sample Output

Case 1: The longest path from 1 has length 1, finishing at 2.
Case 2: The longest path from 3 has length 4, finishing at 5.
Case 3: The longest path from 5 has length 2, finishing at 1.
鎻愪氦浜?0嬈★紝AC 3嬈★紝瓚呮椂4嬈★紝wa 3嬈°?/pre>
寰堟棤璇?/pre>
搴旇鏄姩鎬佽鍒掓渶濂斤紝浣嗘槸鎴戜笉鏄緢鐔燂紝鐢ㄤ簡鎼滅儲銆備互涓嬫槸瓚呮椂鐨勪唬鐮?/pre>
#include<iostream>
#include<cstdlib>
using namespace std;
int path[101][101];
int mark[101];
int len[101];//
int end[101];
int dfs(int start,int num)//榪斿洖浠庡綋鍓嶇偣鍑哄彂鐨勬渶澶ч暱搴?
{
if(mark[start]==1)return len[start];
mark[start]=1;
end[start]=start;
for(int i=1;i<=num;i++)
{
if(path[start][i])
{
if(len[start]<dfs(i,num)+1)
{
len[start]=len[i]+1;
end[start]=end[i];
}
else
if(len[start]==len[i]+1&&end[start]>end[i])
end[start]=end[i];
}
}
mark[start]=0;//榪欏彞鍧氬喅涓嶉渶瑕?
return len[start];
}
int main()
{
// freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
int j,k,turn=0;
int start,num;
while(cin>>num)
{
turn++;
if(num==0)break;
memset(path,0,sizeof(path));
memset(mark,0,sizeof(mark));
memset(len,0,sizeof(len));
memset(end,0,sizeof(end));
cin>>start;
while(cin>>j>>k)
{
if(j==0)break;
path[j][k]=1;
}
cout<<"Case "<<turn<<": The longest path from "<<start<<" has length "<<dfs(start,num)<<", finishing at "<<end[start]<<"."<<endl<<endl;
}
//system("PAUSE");
return   0;
}
浠ヤ笅鏄痑c鐨勪唬鐮?/pre>
#include<iostream>
#include<cstdlib>
using namespace std;
int path[102][102];
int mark[102], len[102],end[102];
int dfs(int start,int num)//榪斿洖浠庡綋鍓嶇偣鍑哄彂鐨勬渶澶ч暱搴?
{
if(mark[start]==1)return len[start];
mark[start]=1;
end[start]=start;
len[start]=0;
int i,t;
for( i=1;i<=num;i++)
{
if(path[start][i])
{
t=dfs(i,num)+1;
if(t>len[start])
{
len[start]=t;
end[start]=end[i];
}
else
if(len[start]==t)
{
if(end[start]>end[i])
end[start]=end[i];
}
}
}
return len[start];
}
int main()
{
//freopen("s.txt","r",stdin);
//freopen("key.txt","w",stdout);
int j,k,turn=0;
int start,num;
while(cin>>num,num)
{
turn++;
memset(path,0,sizeof(path));
memset(mark,0,sizeof(mark));
memset(len,0,sizeof(len));
memset(end,0,sizeof(end));
cin>>start;
while(cin>>j>>k,j||k)
{
path[j][k]=1;
}
dfs(start,num);
cout<<"Case "<<turn<<": The longest path from "<<start<<" has length "<<len[start]<<", finishing at "<<end[start]<<"."<<endl<<endl;
}
//system("PAUSE");
return   0;
}
涓嶅Θ鎵ц涓涓?/pre>
5
3
1 2
3 5
3 1
2 4
4 5
0 0
鍏堟槸len[3]=0;end[3]=3;flag[3]=1;
鍐嶆墽琛宼=dfs(1)+1,
杞叆dfs錛?錛夛紱len[1]=0;end[1]=1;flag[1]=1;
鍐嶆墽琛?span style="COLOR: #0000ff">t=dfs(2)+1;
杞叆dfs(2),len[2]=0;end[2]=2;flag[2]=1;
鍐嶆墽琛宼=dfs(4)+1
杞叆dfs(4),len[4]=0;end[4]=4;flag[4]=1;
鍐嶈漿鍏?span style="COLOR: red">t=dfs錛?)+1;
杞叆dfs(5),len[5]=0;end[5]=5;flag[5]=1;return(len[5]=0);
鍒檛=1;t>len[4];len[4]=1;end[4]=end[5]=5;鍐嶇湅4娌′簡鍏朵粬鐩擱偦鍏冪礌銆俤fs(4)=return(len[4])=1;
t=dfs(4)+1=2;len[2]=t=2;end[2]=end[4]=5;鍐嶇湅2娌′簡鍏朵粬鐩擱偦鍏冪礌錛宒fs(2)=return(len(2)=2;
鍐嶇湅t=dfs(2)+1=3;len[1]=t=3;end[1]=en[2]=5;鍐嶇湅1鏈夋病鏈夊叾浠栫浉閭誨厓绱狅紝dfs(1)=return(len(1)=3
鍐嶆墽琛宼=dfs(1)+1,len[3]=4;end[3]=end[1]=5;鍐嶇湅3鏈夋病鏈夊叾浠栫浉閭誨厓绱狅紝鏈塪fs(5),宸茬粡閬嶅巻鍒頒簡錛屾墍浠fs錛?錛塺eturn len銆?銆戙?br>娌℃湁褰卞搷銆?br>鍋囪鏀逛負
5 3 5 2 3 5 3 1 2 4 4 1 0 0 鎵ц鏃朵細璧?->1>榪欐椂鐨?緇撶偣len[1]宸茬粡姹傜殑 3>5>2>4>1len[1]宸茬煡浜?/span>


luis 2009-06-29 16:13 鍙戣〃璇勮
]]>joj 2173 鏈夌偣鍚彂錛宒ouble榪愮畻閫熷害姣擨nt蹇?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/06/29/88756.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Mon, 29 Jun 2009 03:44:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/06/29/88756.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/88756.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/06/29/88756.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/88756.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/88756.html</trackback:ping><description><![CDATA[<p>鍚彂1錛宒ouble榪愮畻閫熷害姣擨nt蹇?br>鍚彂2錛宮閫塏鐨勭粍鍚堟暟錛屽鏋渘宸茬煡錛屽彧闇寰幆鍗沖彲<br>#include<iostream><br>#include<cstdlib><br>using namespace std;<br>  int main()<br>  {<br>  //freopen("s.txt","r",stdin);<br>  //freopen("key.txt","w",stdout);<br>  double n[1001];<br>  int i,j,k,m;<br>  int flag,num;<br>  while(cin>>num,num)<br>  {<br>  flag=0;<br>  for(m=1;m<=num;m++)<br>  {<br>   cin>>n[m];<br>  }<br>  for(i=1;i<=num;i++)<br>  {<br>    for(j=1;j<=num;j++)<br>     {<br>       for(k=1;k<=num;k++)<br>       {<br>      if(n[i]+n[j]+n[k]==0)<br>     {<br>    flag=1;break;<br>      }<br>       }<br>       if(flag==1)break;<br>   }<br>   if(flag==1)break;<br>   }<br>  if(flag==1)cout<<"yes"<<endl;<br>  else cout<<"no"<<endl;<br> }</p> <p>  //system("PAUSE");<br>  return   0;<br>  }</p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/88756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-06-29 11:44 <a href="http://www.shnenglu.com/luyulaile/archive/2009/06/29/88756.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 2308 Problems to Solve寰堝閥鍟?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/06/28/88729.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sun, 28 Jun 2009 14:26:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/06/28/88729.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/88729.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/06/28/88729.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/88729.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/88729.html</trackback:ping><description><![CDATA[<pre> <pre> <pre> <div id="pd335n3" class=prob_text> <p>Your teacher has given you some problems to solve. You must first solve problem 0. After solving each problem i, you must either move on to problem i+1 or skip ahead to problem i+2. You are not allowed to skip more than one problem. For example, {0, 2, 3, 5} is a valid order, but {0, 2, 4, 7} is not because the skip from 4 to 7 is too long.</p> <p>You are given N integers, where the ith integer indicates how much you like problem i. The teacher will let you stop solving problems once the range of pleasantness you've encountered reaches a certain threshold. Specifically, you may stop once the difference between the maximum and minimum pleasantness of the problems you've solved is greater than or equal to a integer K. If this never happens, you must solve all the problems.</p> <h3>Input</h3> The input contains several test cases. For each case it contains two positive integer N, K (1<=N<=50, 1<=K<=1000), then N integers follow in the next line, the ith integer ( >=1 and <= 1000 ) indicates how much you like problem i.<br> <h3>Output</h3> <p>For each test case, output the minimum number of problems you must solve to satisfy the teacher's requirements.</p> <h3>Sample Input</h3> 3 2<br>1 2 3<br>5 4<br>1 2 3 4 5 <h3>Sample Output</h3> 2<br>3 </div> </pre> <pre>寰堢浣嗘槸寰堝疄鐢紒</pre> <pre>#include<stdio.h> int a[51]; int main() { int n,k; while(scanf("%d%d",&n,&k)!=EOF) { int i,j; for(i=0;i<n;i++) scanf("%d",a+i); int min=0xfffffff; int flag=0; for(i=1;i<n;i++) for(j=0;j<i;j++) { if(a[i]-a[j]>=k||a[j]-a[i]>=k) { flag=1; int step; if(j==0) { step=(i+1)/2+1; if(min>step) min=step; } else { step=(i-j+1)/2+(j+1)/2+1; if(min>step) min=step; } } } if(flag) printf("%d\n",min); else printf("%d\n",n); } return 0; }</pre> </pre> </pre> <img src ="http://www.shnenglu.com/luyulaile/aggbug/88729.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-06-28 22:26 <a href="http://www.shnenglu.com/luyulaile/archive/2009/06/28/88729.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>璁$畻n錛佺殑浣嶆暟錛岄潪甯稿閥濡欏晩錛侊紒http://www.shnenglu.com/luyulaile/archive/2009/06/28/88700.htmlluisluisSun, 28 Jun 2009 09:22:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/28/88700.htmlhttp://www.shnenglu.com/luyulaile/comments/88700.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/06/28/88700.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/88700.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/88700.html#include<iostream> #include<cmath> using namespace std; int main() { int n; double i; long double sum; int sum2; while(cin>>n,n) { sum=1.0; for(i=1.0;i<=n;i++) sum+=log10(i); sum2=sum; printf("%d\n",sum2); } return 0; }
灝嗕箻娉曡漿鍖栦負log鍔犳硶錛侊紒錛?/pre>


luis 2009-06-28 17:22 鍙戣〃璇勮
]]>joj 1026 鍔ㄦ佽鍒掞紝鐢熸垚鍑芥暟鍙婃敼榪?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 27 Jun 2009 02:44:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/88628.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/88628.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/88628.html</trackback:ping><description><![CDATA[<div id="hzxx333" class=prob_text> <p>One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:</p> <p align=center><img height=163 src="http://acm.jlu.edu.cn/joj/images/problems/1026.gif" width=623> </p> <p align=left>Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.</p> <br> <h3>Input</h3> Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input. <p> </p> <p> </p> <br> <h3>Output</h3> Numbers Q, one on each line. <p> </p> <br> <h3>Sample Input</h3> <pre>3 5 0 </pre> <h3>Sample Output</h3> <pre>1 2 </pre> 鏂規硶1錛屽姩鎬佽鍒?br><br>#include<iostream><br>#include<cstdlib><br>using namespace std;<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  double f[501][501]={0};<br>  double s;<br>  int i,j,k,n;<br>  for(i=3;i<=500;i++)<br>  for(j=1;j<=(i-1)/2;j++)<br>    f[i][j]=1;<br>  for(i=3;i<=500;i++)<br>    for(j=1;j<=(i-1)/2;j++)<br>    {<br> for(k=j+1;k<=(i-j-1)/2;k++)<br>   f[i][j]=f[i-j][k]; <br> }<br>    while(scanf("%d",&n),n) { <br>        s=0; <br>        for(i=1;i<=(n-1)/2;i++) s+=f[n][i]; //f[n]=f[n][1]+f[n][2]+-----+f[n][floor((i-1)/2)]<br>        printf("%.0f\n",s); <br>    } <br>  //system("PAUSE");<br>  return   0;<br>  }<br>鏇村鐨勬柟娉曪細鐢熸垚鍑芥暟娉?br>璁$畻(1+x)(1+x^2)(1+x^3)-----,x^n鐨勭郴鏁板嵆涓烘墍姹?br>int i,j;<br>double ans[510]={1,1};//宸茬粡鎶奱ns[1]鍜宎ns[0]璧嬩負1浜嗭紝鍏朵綑涓?<br> for(i=2;i<=500;i++) {   <br>        for(j=500;j>=0;j--) {  <br>            if(i+j<=500) ans[i+j]+=ans[j]; <br>        }  <br>    }  <br><br>鍏堣綆?1+x)(1+x^2)<br>鍐嶈綆?1+x)(1+x^2)   *(1+x^3)<br></div> <img src ="http://www.shnenglu.com/luyulaile/aggbug/88628.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-06-27 10:44 <a href="http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>map緇忓吀鐢ㄦ硶+澶氫釜絀烘牸闅斿紑鐨刢ase 鑾峰彇琛屽瓧絎︿覆http://www.shnenglu.com/luyulaile/archive/2009/06/27/88622.htmlluisluisSat, 27 Jun 2009 01:05:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/27/88622.html#include<iostream>
#include
<string>
#include
<map>
using namespace std;

int main()
{
    
//freopen("s.txt","r",stdin);
  
//freopen("key.txt","w",stdout); 
    string s;
    
int g=0;
    
while(getline(cin,s))
    {
        
if (g) cout<<endl;
        g
=1;
        
int sum=0;
        map
<string,int> a;
        
while(s!="")
        {
            a[s]
++;
            sum
++;
            getline(cin,s);
        }
        cout.flags(ios::
fixed);
        cout.precision(
4);
        
for (map<string,int>::iterator p=a.begin();p!=a.end();p++)
            cout
<<p->first<<" "<<100.0*p->second/sum<<endl;
    }
    
return 0;
}

#include<iostream>
#include<string>
#include<map>
using namespace std;

int main()
{
 freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
    string s;
    int g=0;
    while(getline(cin,s))
    {
        if (g) cout<<endl;
        g=1;
        int sum=0;
        map<string,int> a;
        while(s!="")
        {
            a[s]++;
            sum++;
            getline(cin,s);
        }
        cout.flags(ios::fixed);
        cout.precision(4);
        for (map<string,int>::iterator p=a.begin();p!=a.end();p++)
            cout<<p->first<<" "<<100.0*p->second/sum<<endl;
    }
    return 0;
}

 



luis 2009-06-27 09:05 鍙戣〃璇勮
]]>
joj 1197 &&poj 1564 Sum It Up,寰堝閥濡欏鐞嗘湁閲嶅鐨勬繁鎼滃壀鏋?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 14 May 2009 08:32:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/82965.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/82965.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/82965.html</trackback:ping><description><![CDATA[Sum It Up <hr> <table cellSpacing=3 cellPadding=3 width="75%" border=1> <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7> <tbody> <tr> <th height=40>Status</th> <th>In/Out</th> <th>TIME Limit</th> <th>MEMORY Limit</th> <th>Submit Times</th> <th>Solved Users</th> <th>JUDGE TYPE</th> </tr> <tr> <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td> <td>stdin/stdout</td> <td>3s</td> <td>8192K</td> <td>424</td> <td>182</td> <td>Standard</td> </tr> </tbody> </table> <div id="pz335z5" class=prob_text> <p>Given a specifie d total <em>t</em> and a list of <em>n</em> integers, find all distinct sums using numbers from the list that add up to <em>t</em>. For example, if <em>t</em> = 4, <em>n</em> = 6, and the list is [4, 3, 2, 2, 1, 1], then there are four different sums that equal 4: 4, 3+1, 2+2, and 2+1+1. (A number can be used within a sum as many times as it appears in the list, and a single number counts as a sum.) Your job is to solve this problem in general. </p> <p> <h3>Input</h3> <p>The input file will contain one or more test cases, one per line. Each test case contains <em>t</em>, the total, followed by <em>n</em>, the number of integers in the list, followed by <em>n</em> integers <img height=30 src="http://acm.jlu.edu.cn/joj/images/problems/1197.gif" width=80 align=middle border=0>. If <em>n</em> = 0 it signals the end of the input; otherwise, <em>t</em> will be a positive integer less than 1000, <em>n</em> will be an integer between 1 and 12 (inclusive), and <img height=30 src="http://acm.jlu.edu.cn/joj/images/problems/1197.gif" width=80 align=middle border=0> will be positive integers less than 100. All numbers will be separated by exactly one space. The numbers in each list appear in nonincreasing order, and there may be repetitions. </p> <p> <h3>Output</h3> <p>For each test case, first output a line containing `<tt>Sums of </tt>', the total, and a colon. Then output each sum, one per line; if there are no sums, output the line `<tt>NONE</tt>'. The numbers within each sum must appear in nonincreasing order. A number may be repeated in the sum as many times as it was repeated in the original list. The sums themselves must be sorted in decreasing order based on the numbers appearing in the sum. In other words, the sums must be sorted by their first number; sums with the same first number must be sorted by their second number; sums with the same first two numbers must be sorted by their third number; and so on. Within each test case, all sums must be distinct; the same sum cannot appear twice. </p> <p> <h3>Sample Input</h3> <pre>4 6 4 3 2 2 1 1 5 3 2 1 1 400 12 50 50 50 50 50 50 25 25 25 25 25 25 0 0 </pre> <p> <h3>Sample Output</h3> <pre>Sums of 4: 4 3+1 2+2 2+1+1 Sums of 5: NONE Sums of 400: 50+50+50+50+50+50+25+25+25+25 50+50+50+50+50+25+25+25+25+25+25 <br></pre> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">cstdlib</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">memory</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mount;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> l;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> a[</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> mark;<br>  </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> output()<br>  {<br>    mark</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;   <br>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp[</span><span style="COLOR: #000000">12</span><span style="COLOR: #000000">];   <br>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {  <br>     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">])<br>    {<br>      </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(flag</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>      flag</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br>      </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>      cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br>     cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>     }                          <br>    }          <br>     cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;            <br>  }<br>  </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> dfs(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> nowv,</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pre)<br>  {<br>       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> value;<br>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nowv</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">sum)<br>       {<br>          output();         <br>       }<br>       </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br>       {<br>           </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">pre</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>           {<br>             value</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[j][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];      <br>             </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(nowv</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">value</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">value</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">l)<br>             { <br>             a[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;                                                       <br>             dfs(sum,nowv</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">value,j);<br>             a[j][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>             }   <br>           }<br>       }<br>       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(pre</span><span style="COLOR: #000000">!=-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br>       l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">a[pre][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>  }<br>  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>  {<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen("s.txt","r",stdin);<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">freopen("key.txt","w",stdout);</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> sum,i,j;<br>  cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">mount;<br>  </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(sum</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>  {           <br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">mount;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>       cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">a[i][</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">];<br>       a[i][</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;      <br>    }<br>    <br>    mark</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    l</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Sums of </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br>    dfs(sum,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">);<br>    </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(mark</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">NONE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;         <br>    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">sum</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">mount;         <br>  }<br>  </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">system("PAUSE");</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">  </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>  }<br></span></div> <p> </p> 闅劇偣錛?錛屾湁搴忛掑噺錛岃繖涓ソ澶勭悊錛屽彧闇鍦ㄥ悜鍓嶆帹鏃禿fs(i)for(int j=i+1...)鍗沖彲<br>            2錛屽幓鎺夋棤鏁堢殑閲嶅鎼滅儲錛岃繖涓儲涓鐐?姣斿鍜屼負11鏃訛紝搴忓垪涓?,6,6,2,2,2,1錛?+2+2+1鏄劇劧鏄彲浠ョ殑錛屼絾鏄?+6涓嶅彲浠ャ?+6+6鏇翠笉鍙互<br>鎴戜滑鍙互榪欐牱鎯籌紝濡傛灉欏虹潃寰鍓嶆帹鏄紝濡傛灉涓嶈秴榪囪寖鍥達紝姣斿6+2+鍙栧悗涓涓暟鏃訛紝2鍙互鍙栵紝浣嗘槸6+6錛岃秴榪?1錛岃鍥炴函鐨勬椂鍊欙紝璁板綍涓嬫鏃剁殑6錛岀敤涓嬮潰鐨勪唬鐮?br><br>if(pre!=-1)<br>       l=a[pre][0];<br><br>鍦ㄦ瘮杈僫f(nowv+value<=sum&&value!=l)姝ゆ椂涓嶇鍚堬紝涓嬩竴涓?鍙栦笉鍒頒簡錛侀伩鍏嶄簡閲嶅銆?/div> <img src ="http://www.shnenglu.com/luyulaile/aggbug/82965.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-05-14 16:32 <a href="http://www.shnenglu.com/luyulaile/archive/2009/05/14/82965.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.veixzew.cn" target="_blank">国产精品久久久久a影院</a>| <a href="http://www.jhgppeizi.com.cn" target="_blank">精品久久一区二区</a>| <a href="http://www.7788mm.cn" target="_blank">亚洲中文字幕久久精品无码APP</a>| <a href="http://www.e-zhishi.cn" target="_blank">久久久久久久久66精品片</a>| <a href="http://www.lsjtht.cn" target="_blank">亚洲综合熟女久久久30p</a>| <a href="http://www.vyfx.cn" target="_blank">精品久久久久久</a>| <a href="http://www.or-z.cn" target="_blank">久久精品无码一区二区WWW</a>| <a href="http://www.wdxxz.cn" target="_blank">狠色狠色狠狠色综合久久</a>| <a href="http://www.montblanc-fola.cn" target="_blank">精品久久久久中文字幕一区</a>| <a href="http://www.gdhaojulai.cn" target="_blank">久久毛片一区二区</a>| <a href="http://www.angcao.cn" target="_blank">亚洲国产精品久久久久婷婷老年 </a>| <a href="http://www.wushuichulisb.cn" target="_blank">51久久夜色精品国产</a>| <a href="http://www.mt4.net.cn" target="_blank">日韩va亚洲va欧美va久久</a>| <a href="http://www.u33w.cn" target="_blank">色欲综合久久躁天天躁蜜桃</a>| <a href="http://www.gongyeyongbu.com.cn" target="_blank">国产一区二区精品久久</a>| <a href="http://www.eiszar86.cn" target="_blank">一本久久免费视频</a>| <a href="http://www.vcexpress.cn" target="_blank">久久综合狠狠色综合伊人</a>| <a href="http://www.88kam.cn" target="_blank">久久这里只有精品首页</a>| <a href="http://www.gold160.cn" target="_blank">久久久久久国产精品无码下载 </a>| <a href="http://www.shenghuigd.com.cn" target="_blank">久久天天躁狠狠躁夜夜躁2014</a>| <a href="http://www.lkzcchj1.cn" target="_blank">久久超碰97人人做人人爱</a>| <a href="http://www.114best.com.cn" target="_blank">久久久久久一区国产精品</a>| <a href="http://www.77ns.cn" target="_blank">国产婷婷成人久久Av免费高清</a>| <a href="http://www.zdjbc1.cn" target="_blank">久久AAAA片一区二区</a>| <a href="http://www.cgjiamei.cn" target="_blank">国产精品久久久久久久久免费</a>| <a href="http://www.uugp.cn" target="_blank">亚洲中文字幕无码久久2020</a>| <a href="http://www.bxzpzlb.cn" target="_blank">久久996热精品xxxx</a>| <a href="http://www.sem588.cn" target="_blank">91亚洲国产成人久久精品网址</a>| <a href="http://www.t55n3z.cn" target="_blank">一本一本久久A久久综合精品</a>| <a href="http://www.greektaverna.cn" target="_blank">精品一久久香蕉国产线看播放</a>| <a href="http://www.phb321.cn" target="_blank">色综合合久久天天综合绕视看 </a>| <a href="http://www.kukuoo.cn" target="_blank">老色鬼久久亚洲AV综合</a>| <a href="http://www.jbl21.cn" target="_blank">久久亚洲AV无码精品色午夜麻豆</a>| <a href="http://www.qhklmy.cn" target="_blank">国产精品久久久久久福利漫画</a>| <a href="http://www.iceplaza.cn" target="_blank">人妻精品久久无码专区精东影业</a>| <a href="http://www.68360.cn" target="_blank">无码8090精品久久一区</a>| <a href="http://www.dnsdna.cn" target="_blank">久久久久亚洲av成人无码电影</a>| <a href="http://www.axtea2007.cn" target="_blank">国产精品一区二区久久精品无码 </a>| <a href="http://www.aoshidun.com.cn" target="_blank">国产精品熟女福利久久AV</a>| <a href="http://www.qeckf.cn" target="_blank">久久精品国产免费一区</a>| <a href="http://www.vhxz.cn" target="_blank">麻豆精品久久精品色综合</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>