1219 水~
View Code
1 #include2 #include 3 const int maxn = 30; 4 int a[ maxn ]; 5 char s[ 100005 ]; 6 int main(){ 7 while( gets( s )!=NULL ){ 8 memset( a,0,sizeof( a ) ); 9 int len=strlen( s );10 for( int i=0;i ='a'&&s[i]<='z' )12 a[ s[i]-'a' ]++;13 }14 for( int i=0;i<26;i++ ){15 printf("%c:%d\n",i+'a',a[i]);16 }17 printf("\n");18 }19 return 0;20 }
1222
我是找规律的。。。对于n,m,如果他们之间有公共约数,则说明在狼走第二圈的时候,会走重复的点。
View Code
1 #include2 int gcd( int a,int b ){ 3 int r; 4 while( b ){ 5 r=a%b; 6 a=b; 7 b=r; 8 } 9 return a;10 }11 int main(){12 int t;13 scanf("%d",&t);14 while(t--){15 int n,m;16 scanf("%d%d",&m,&n);17 //while( m>n )18 //m-=n;19 if( m==1||n==1 ){20 printf("NO\n");21 continue;22 }23 if( m==n ){24 printf("YES\n");25 continue;26 }27 if( gcd(n,m)!=1 ){28 printf("YES\n");29 }30 else{31 printf("NO\n");32 }33 }34 return 0;35 }
1224
SPFA 挺水的~~~
简单题吧
View Code s; 63 for( int i=n+1;i!=-1;i=path[i] ){ 64 s.push( i ); 65 } 66 printf("circuit : "); 67 printf("%d",s.top()); 68 s.pop(); 69 while( !s.empty() ){ 70 if( s.top()==(n+1) ) 71 printf("->%d",1); 72 else 73 printf("->%d",s.top()); 74 s.pop(); 75 } 76 printf("\n"); 77 } 78 int main(){ 79 int T; 80 scanf("%d",&T); 81 for( int ca=1;ca<=T;ca++ ){ 82 if( ca!=1 ) 83 printf("\n"); 84 scanf("%d",&n); 85 for( int i=1;i<=n;i++ ) 86 scanf("%d",&val[ i ]); 87 val[n+1]=0; 88 scanf("%d",&m); 89 int a,b; 90 init(); 91 while( m-- ){ 92 scanf("%d%d",&a,&b); 93 if( a b ){ 97 addedge( b,a,0 ); 98 } 99 }100 bfs();101 printf("CASE %d#\n",ca);102 //printf("%d\n",dis[n+1]);103 output();104 }105 return 0;106 }
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 const int maxn = 105; 9 const int maxm = 10000; 10 const int inf = 99999999; 11 int cnt,head[ maxn ]; 12 struct node{ 13 int u,val,next; 14 }edge[ maxm ]; 15 int n,m; 16 int val[ maxn ]; 17 int dis[ maxn ],vis[ maxn ],path[ maxn ]; 18 19 void init(){ 20 cnt=0; 21 memset( head,-1,sizeof( head )); 22 } 23 24 void addedge( int a,int b,int c ){ 25 edge[ cnt ].u=b; 26 edge[ cnt ].val=c; 27 edge[ cnt ].next=head[ a ]; 28 head[ a ]=cnt++; 29 } 30 31 void bfs(){ 32 for( int i=1;i<=n+1;i++ ){ 33 vis[i]=0; 34 dis[i]=-inf; 35 path[i]=-1; 36 } 37 queue q; 38 while( !q.empty() ) 39 q.pop(); 40 q.push( 1 ); 41 vis[1]=1; 42 dis[1]=0; 43 while( !q.empty() ){ 44 int now=q.front(); 45 q.pop(); 46 vis[ now ]=0; 47 for( int i=head[ now ];i!=-1;i=edge[ i ].next ){ 48 int next=edge[i].u; 49 if( dis[next]