#18041: NA 94% 還有什麼能優化的地方嗎?


rmp4joxj6 (盧邊談話)


#4: 3% TLE (2s)

Killed

#5: 3% TLE (2s)

Killed

#include <iostream>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int dot,side,DOT1,DOT2,test;
  while(cin>>dot>>side){
    int flag[dot]={0};
    test=0;
    for(int a=1;a<=side;a++){
      cin>>DOT1>>DOT2;
      flag[DOT1-1]++,flag[DOT2-1]++;
    }
    if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){       //測頭尾
      cout<<"NO\n";                                                                                                         
      continue;                                                                                                              
    }
    for(int a=1;a<=dot-2;a++){                                                                                       //測中間
      if(flag[a]%2==1){
        test=1;
        break;
      }
    }
    if(test){
      cout<<"NO\n";
    }else{
      cout<<"YES\n";
    }
  }
}

#18045: Re:NA 94% 還有什麼能優化的地方嗎?


icube (!@#$%^&*()_+)


改用 scanf 進行輸入

 
#18050: Re:NA 94% 還有什麼能優化的地方嗎?


rmp4joxj6 (盧邊談話)


改用 scanf 進行輸入

 

我改成scanf,printf後,反而全TLE了,我對scanf,printf不熟,請問有什麼錯誤的地方嗎?

更動的地方紅色字體標示

 

#include <stdio.h>

using namespace std;

int main(){

  int dot,side,DOT1,DOT2,test;

  while(scanf("%d%d",&dot,&side)){

      int flag[dot]={0};

      test=0;

      for(int a=1;a<=side;a++){

          scanf("%d%d",&DOT1,&DOT2);

 

  flag[DOT1-1]++,flag[DOT2-1]++;

      }

      if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){

 printf("%s\n","NO");

 

 continue;

      }

      for(int a=1;a<=dot-2;a++){

 if(flag[a]%2==1){

   test=1;

   break;

 }

      }

      if(test){

printf("%s\n","NO");

 

      }else{

printf("%s\n","YES");

      }

   } 

}

 

 

#18051: Re:NA 94% 還有什麼能優化的地方嗎?


icube (!@#$%^&*()_+)


#18400: Re:NA 94% 還有什麼能優化的地方嗎?


rexwu1104@gmail.com (黑雪公主 Black Lotus)


改用 scanf 進行輸入

 

我改成scanf,printf後,反而全TLE了,我對scanf,printf不熟,請問有什麼錯誤的地方嗎?

更動的地方紅色字體標示

 

#include

using namespace std;

int main(){

  int dot,side,DOT1,DOT2,test;

  while(scanf("%d%d",&dot,&side)!=EOF){

      int flag[dot]={0};

      test=0;

      for(int a=1;a<=side;a++){

          scanf("%d%d",&DOT1,&DOT2);

 

  flag[DOT1-1]++,flag[DOT2-1]++;

      }

      if( (flag[0]%2==0&&flag[dot-1]%2==1) || (flag[0]%2==1&&flag[dot-1]%2==0) ){

 printf("%s\n","NO");

 

 continue;

      }

      for(int a=1;a<=dot-2;a++){

 if(flag[a]%2==1){

   test=1;

   break;

 }

      }

      if(test){

printf("%s\n","NO");

 

      }else{

printf("%s\n","YES");

      }

   } 

}