博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1219-1226(杭州电子科技大学第三届程序设计大赛+部分题解)
阅读量:4620 次
发布时间:2019-06-09

本文共 6746 字,大约阅读时间需要 22 分钟。

1219 水~

View Code
1 #include
2 #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 #include
2 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
1 #include
2 #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]
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 }

 1225

字符串的水题~~~

View Code
1 #include
2 #include
3 #include
4 using namespace std; 5 const int maxn = 5005; 6 struct node{ 7 char name[ 105 ]; 8 int win,lost,diff,score; 9 }team[ maxn ];10 int cnt;11 void init( int n ){12 for( int i=0;i<=n;i++ ){13 team[ i ].win=team[ i ].lost=team[ i ].diff=team[ i ].score=0;14 //memset( team[i].name,'\0',sizeof( team[i].name ));15 }16 cnt=0;17 }18 int find( char tt[] ){19 if( cnt==0 ){20 strcpy( team[0].name,tt );21 cnt++;22 return 0;23 }24 int i;25 for( i=0;i
b.score;39 else if( a.diff!=b.diff )40 return a.diff>b.diff;41 else if( a.win!=b.win )42 return a.win>b.win;43 else if( strcmp( a.name,b.name )>0 )44 return false;45 else return true;46 }47 int main(){48 int n;49 while( scanf("%d",&n)!=EOF ){50 init( n );51 char n1[ 105 ],n2[ 105 ];52 int num1,num2;53 for( int i=0;i<(n*(n-1));i++ ){54 scanf("%s VS %s %d:%d",n1,n2,&num1,&num2);55 int f1=find( n1 );56 int f2=find( n2 );57 if( num1==num2 ){58 team[ f1 ].score++;59 team[ f2 ].score++;60 team[ f1 ].win+=num1;61 team[ f1 ].lost+=num1;62 team[ f2 ].win+=num2;63 team[ f2 ].lost+=num2;64 }65 else if( num1>num2 ){66 team[ f1 ].win+=num1;67 team[ f1 ].lost+=num2;68 team[ f2 ].win+=num2;69 team[ f2 ].lost+=num1;70 team[ f1 ].score+=3;71 }72 else if( num1

 1226

BFS+5000个状态+mod!!!

View Code
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 const int maxn = 24; 10 const int maxm = 5105; 11 const int inf = 99999999; 12 int n,m,c; 13 int a[ maxn ]; 14 int vis[ maxm ]; 15 int flag; 16 struct node{ 17 string ans; 18 int mod; 19 }; 20 string res; 21 queue
q; 22 void init2(){ 23 while( !q.empty() ) 24 q.pop(); 25 } 26 void init1(){ 27 memset( a,0,sizeof( a )); 28 memset( vis,0,sizeof( vis )); 29 flag=-1; 30 res.clear(); 31 } 32 void bfs(){ 33 init2(); 34 node now,next; 35 for( int i=1;i<16;i++ ){ 36 if( a[i] ){ 37 vis[ i%n ]=1; 38 if( i>=0&&i<=9 ){ 39 now.ans=""; 40 now.ans=(i+'0'); 41 now.mod=i%n; 42 q.push( now ); 43 } 44 else{ 45 now.ans=""; 46 now.ans=(i+'A'-10); 47 now.mod=i%n; 48 q.push( now ); 49 } 50 } 51 }//the init 52 while( !q.empty() ){ 53 now=q.front(),q.pop(); 54 if( flag==1&&now.ans.size()>res.size() ) 55 continue; 56 if( now.mod==0 ){ 57 if( flag==-1 ){ 58 flag=1; 59 res=now.ans; 60 } 61 else{ 62 if( now.ans.size()
now.ans ){ 66 res=now.ans; 67 } 68 } 69 } 70 for( int i=0;i<16;i++ ){ 71 if( a[i] ){ 72 if( i<10 ){ 73 next=now; 74 next.ans+=( i+'0' ); 75 next.mod=(now.mod*c+i)%n; 76 if( ( next.ans.size()<=500&&vis[ next.mod ]==0 )||( next.mod==0 ) ){ 77 vis[ next.mod ]=1; 78 q.push( next ); 79 } 80 } 81 else{ 82 next=now; 83 next.ans+=(i+'A'-10); 84 next.mod=(now.mod*c+i)%n; 85 if( ( next.ans.size()<=500&&vis[ next.mod ]==0 )||( next.mod==0 ) ){ 86 vis[ next.mod ]=1; 87 q.push( next ); 88 } 89 } 90 } 91 } 92 } 93 } 94 95 int main(){ 96 int ca; 97 scanf("%d",&ca); 98 while( ca-- ){ 99 scanf("%d%d%d",&n,&c,&m);100 init1();101 char ch[ 4 ];102 for( int i=0;i
='0'&&ch[0]<='9' )105 a[ ch[0]-'0' ]=1;106 else107 a[ ch[0]-'A'+10 ]=1;108 }109 if(n==0){ 110 // cout<<0<

 

转载于:https://www.cnblogs.com/xxx0624/archive/2013/02/26/2934021.html

你可能感兴趣的文章
安装ejabberd2并配置MySQL为其数据库
查看>>
angular repeat
查看>>
android 图片圆角化控件
查看>>
java第三次作业
查看>>
HP Jack介绍
查看>>
敏捷软件开发(3)---COMMAND 模式 & Active Object 模式
查看>>
poj 1062 昂贵的聘礼 解题报告
查看>>
get the page name from url
查看>>
visual studio中csproj文件中的project guid改为小写 ( notepad++ 正则)
查看>>
TeeChart显示三维的图形,使用Surface
查看>>
如何使用 Idea 远程调试 Java 代码
查看>>
加密,解密
查看>>
在C#代码中应用Log4Net(一)简单使用Log4Net
查看>>
[转]如何写软件项目技术标
查看>>
每日站立会议个人博客五
查看>>
ddd
查看>>
死磕 java同步系列之AQS起篇
查看>>
利用Lucene把文本的字体格式进行改动,然后输出到一个新的文件里
查看>>
[Openstack] Expecting an auth URL via either --os-auth-url or env[OS_AUTH_URL]
查看>>
How to Create Modifiers Using the API QP_MODIFIERS_PUB.PROCESS_MODIFIERS
查看>>