24h購物| | PChome| 登入
2009-02-14 19:54:26| 人氣500| 回應0 | 上一篇 | 下一篇

2007 NPSC C. 小姐,我認識妳嗎?

推薦 0 收藏 0 轉貼0 訂閱站台

題目看似複雜,內容只有一小部分

/***********************************************************/

  1. #include<stdio.h>   
  2. #include<stdlib.h>   
  3. main()   
  4. {   
  5.  int m,n;   
  6.  while(scanf("%d %d",&m,&n)==2&&m!=0)   
  7.   {   
  8.    int math[101]={0},ans=0,time=0,a;   
  9.    for(a=0;a<n;a++)   
  10.     {   
  11.      int t,w,g;   
  12.      scanf("%d %d %d",&t,&w,&g);   
  13.      if(math[w]==-1) continue;   
  14.      if(g==0) math[w]++;   
  15.      else  
  16.       {   
  17.        time++;   
  18.        ans=ans+t+math[w]*20;   
  19.        math[w]=-1;   
  20.       }   
  21.     }    
  22.     printf("%d %d\n",ans,time);   
  23.   }   
  24.  return  0;   

/********************************/

輸入很多,來個優化輸入吧!

#include<stdio.h>     
#include<stdlib.h>     
#include<math.h>     
int input()  
{  
  char cha;  
  int x=0,flag=1;  
  while(cha=getchar())  
     if(cha!=' '&&cha!='\n') break;  
   if(cha!='-')
       x=x*10+cha-48; 
   else flag=-1;  
  while(cha=getchar())   
    {  
     if(cha==' '||cha=='\n') break;  
      x=x*10+cha-48;  
    }  
    return x*flag;  
}
main()
{
 int m,n;
 while(scanf("%d %d",&m,&n)==2&&m!=0)
  {
   int math[101]={0},ans=0,time=0,a;
   for(a=0;a<n;a++)
    {
     int t,w,g;
     t=input();
     w=input();
     g=input();
     if(math[w]==-1) continue;
     if(g==0) math[w]++;
     else
      {
       time++;
       ans=ans+t+math[w]*20;
       math[w]=-1;
      }
    }
    printf("%d %d\n",ans,time);
  }
 return  0;
}

台長: 來源不明
人氣(500) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: NPSC |
此分類下一篇:2006 NPSC F. 假日的奇想曲
此分類上一篇:2007 NPSC G. 折方塊

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文