zoukankan      html  css  js  c++  java
  • 哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)

    A.小乐乐学走路

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 int n;int x;
     5 int main(){
     6     while(cin>>n){
     7         getchar();
     8         while(n--){
     9             cin>>x;
    10             cout<<(char)x;
    11         }
    12         puts("");
    13     }
    14     return 0;
    15 }
    View Code

    B.小乐乐搭积木

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 int n,cnt,x,tmp;
     5 int main(){
     6     while(cin>>n){
     7         cin>>x,tmp=x,cnt=1;
     8         while(--n){
     9             cin>>x;
    10             if(x>=tmp)cnt++,tmp=x;
    11         }
    12         cout<<cnt<<endl;
    13     }
    14     return 0;
    15 }
    View Code

    C.小乐乐玩木桶:短板原理。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 int a,b,c;
     5 int main(){
     6     while(cin>>a>>b>>c){
     7         cout<<min(a,min(b,c))<<endl;
     8     }
     9     return 0;
    10 }
    View Code

    D.小乐乐上学记

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 int n;
     5 int main(){
     6     while(cin>>n){
     7         for(int i=1;i<=n;++i){
     8             for(int j=n-i;j>0;--j)printf(" ");
     9             for(int j=1;j<=2*i-1;++j)printf("*");
    10             puts("");
    11         }
    12     }
    13     return 0;
    14 }
    View Code

    E.小乐乐打游戏:简单的bfs+曼哈顿距离,只要起点S能到达终点E,并且花费的最少步数不大于F到E的曼哈顿距离就能吃猪!

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn=1005;
     5 int n,m,dir[4][2]={{1,0},{-1,0},{0,-1},{0,1}};char mp[maxn][maxn];
     6 int fx,fy,sx,sy,ex,ey,ans;bool vis[maxn][maxn];
     7 struct node{int x,y,step;}tmp,nod;
     8 queue<node> que;
     9 int bfs(int x,int y){
    10     while(!que.empty())que.pop();
    11     tmp.x=x,tmp.y=y,tmp.step=0;
    12     que.push(tmp),vis[x][y]=true;
    13     while(!que.empty()){
    14         nod=que.front(),que.pop();
    15         if(nod.x==ex&&nod.y==ey)return nod.step;
    16         for(int i=0;i<4;++i){
    17             int nx=nod.x+dir[i][0],ny=nod.y+dir[i][1];
    18             if(nx>=0&&ny>=0&&nx<n&&ny<m&&!vis[nx][ny]&&mp[nx][ny]!='#'){
    19                 vis[nx][ny]=true;
    20                 tmp.x=nx,tmp.y=ny,tmp.step=nod.step+1;
    21                 que.push(tmp);
    22             }
    23         }
    24     }
    25     return 0;
    26 }
    27 int main(){
    28     while(cin>>n>>m){
    29         for(int i=0;i<n;++i)cin>>mp[i];
    30         for(int i=0;i<n;++i){
    31             for(int j=0;j<m;++j){
    32                 if(mp[i][j]=='S')sx=i,sy=j;
    33                 else if(mp[i][j]=='F')fx=i,fy=j;
    34                 else if(mp[i][j]=='E')ex=i,ey=j;
    35             }
    36         }
    37         memset(vis,false,sizeof(vis));
    38         ans=bfs(sx,sy);
    39         if(ans&&ans<=abs(fx-ex)+abs(fy-ey))puts("PIG PIG PIG!");
    40         else puts("A! WO SI LA!");
    41     }
    42     return 0;
    43 }
    View Code

    F.小乐乐下象棋

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 char str[1005];
     5 int main(){
     6     while(gets(str)){
     7         for(int i=0;str[i];++i)
     8             if(str[i]!=' ')printf("%c",str[i]);
     9         puts("");
    10     }
    11     return 0;
    12 }
    View Code

    G.小乐乐打游戏:典型的斐波那契博弈。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int n,fib[44]={2,3};bool flag;
     5     for(int i=2;i<44;++i)
     6         fib[i]=fib[i-1]+fib[i-2];
     7     while(cin>>n){
     8         flag=false;
     9         for(int i=0;i<44;++i)
    10             if(fib[i]==n){flag=true;break;}
    11         if(flag)cout<<"Big"<<endl;
    12         else cout<<"Small"<<endl;
    13     }
    14     return 0;
    15 }
    View Code

    H.小乐乐的组合数:暴力枚举即可。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 int n,m,cnt;
     5 int main(){
     6     while(cin>>n>>m){
     7         cnt=0;
     8         for(int i=1;i<=n;++i)
     9             for(int j=1;j<=m;++j)
    10                 if((i+j)%7==0)cnt++;
    11         cout<<cnt<<endl;
    12     }
    13     return 0;
    14 }
    View Code

    I.小乐乐切割方块:中心四个方格都不满足。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,x,y;
     4 int main(){
     5     while(cin>>n>>x>>y){
     6         n/=2;
     7         if((x==n||x==n+1)&&(y==n||y==n+1))puts("No");
     8         else puts("Yes");
     9     }
    10     return 0;
    11 }
    View Code

    J.小乐乐算数字

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 LL n,ans;
     5 int main(){
     6     while(cin>>n){
     7         ans=1LL;
     8        for(LL i=2LL;i<=n;i<<=1)
     9         if(n%i==0)ans=i;
    10     cout<<ans<<endl;
    11     }
    12     return 0;
    13 }
    View Code
  • 相关阅读:
    Entity SQL 初入
    ObjectQuery查询及方法
    Entity Framework 的事务 DbTransaction
    Construct Binary Tree from Preorder and Inorder Traversal
    Reverse Linked List
    Best Time to Buy and Sell Stock
    Remove Duplicates from Sorted Array II
    Reverse Integer
    Implement Stack using Queues
    C++中const限定符的应用
  • 原文地址:https://www.cnblogs.com/acgoto/p/10074125.html
Copyright © 2011-2022 走看看