zoukankan      html  css  js  c++  java
  • 模拟2

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    A.
    d.按要求输出'N'就行了。注意字母是连续使用的,而不是再从'a'开始。
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    
    char str[16][16];
    int t;
    
    void display(int n){
    
        int i,j;
    
        for(i=0;i<16;++i){
            for(j=0;j<16;++j){
                str[i][j]=' ';
            }
        }
    
        for(i=0,j=0;i<n;++i){
            str[i][j]='a'+t;
            t=(t+1)%26;
        }
    
        for(i=n-2,j=1;i>0&&j<n-1;--i,++j){
            str[i][j]='a'+t;
            t=(t+1)%26;
        }
    
        for(i=0,j=n-1;i<n;++i){
            str[i][j]='a'+t;
            t=(t+1)%26;
        }
    
        for(i=0;i<n;++i){
            for(j=0;j<n;++j){
                printf("%c",str[i][j]);
            }
            printf("
    ");
        }
    }
    
    int main(){
    
        int i;
    
        t=0;
        for(i=3;i<=10;++i){
            display(i);
        }
    
        return 0;
    }
    View Code
    B.
    d.这个题意啊。。。尴尬。。三天没找到仓鼠,说明它在诱捕的有效范围之外。。
    ps:nearer than是小于等于的意思吗?怎么感觉是小于呢。。不过这题从样例可以得知是小于等于。
    s.直接bfs
    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<queue>
    using namespace std;
    
    #define MAXN 200005
    
    int sum;
    int D;
    int dis[MAXN];
    bool vis[MAXN];
    
    struct Edge{
        int to,next;
    }edge[MAXN];
    int head[MAXN],tot;
    
    void addedge(int u,int v){
        edge[tot].to=v;
        edge[tot].next=head[u];
        head[u]=tot++;
    
    }
    
    void init(){
        tot=0;
        memset(head,-1,sizeof(head));
        memset(vis,false,sizeof(vis));
    }
    
    void bfs(int u){
    
        queue<int> myQueue;
        myQueue.push(0);
        dis[0]=0;
        vis[0]=true;
        ++sum;
        int i;
        int v;
    
        while(!myQueue.empty()){
            v=myQueue.front();
            myQueue.pop();
    
            for(i=head[v];i!=-1;i=edge[i].next){
    
                if(dis[v]+1<=D&&!vis[edge[i].to]){
                    myQueue.push(edge[i].to);
                    dis[edge[i].to]=dis[v]+1;
                    vis[edge[i].to]=true;
                    ++sum;
                }
            }
    
        }
    
    }
    
    int main(){
    
        int T;
        int N;
        int x,y;
        int i;
    
        scanf("%d",&T);
    
        while(T--){
            scanf("%d%d",&N,&D);
    
            init();
            for(i=1;i<N;++i){
                scanf("%d%d",&x,&y);
                addedge(x,y);
                addedge(y,x);
            }
    
            sum=0;
    
            bfs(0);
    
            printf("%d
    ",N-sum);
        }
    
        return 0;
    }
    View Code
    C.
    d.一圈是一层,求旋转的最少次数,使对角线和最大。
    s.找规律
    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    
    int ma[16][16];
    int sum[10][10];
    int q[12]={0,1,2,3,4,5,6,7,8,9,10,11};
    
    int main(){
    
        int n;
        int i,j;
        int t;
        int k;
        int ma_sum,ma_loc;
        int tol_sum;
        int tol_step;
    
        while(~scanf("%d",&n)){
            if(n==0){
                break;
            }
    
            for(i=0;i<n;++i){
                for(j=0;j<n;++j){
                    scanf("%d",&ma[i][j]);
                }
            }
    
            t=n/2;
            memset(sum,0,sizeof(sum));
            tol_sum=0;
            tol_step=0;
            for(i=0;i<t;++i){
                ma_sum=0;
                for(j=0;j<(i+1)*2;++j){
                    sum[i][j]=ma[t-i-1+q[j]][t-i-1]+ma[t+i+1][t-i-1+q[j]]+ma[t+i+1-q[j]][t+i+1]+ma[t-i-1][t+i+1-q[j]];//主要是这个地方,写对就差不多了。
                    if(sum[i][j]>ma_sum){
                        ma_sum=sum[i][j];
                        ma_loc=j;
                    }
                }
                if(ma_loc-0<(i+1)*2-ma_loc){
                    tol_step+=ma_loc;
                }
                else{
                    tol_step+=(i+1)*2-ma_loc;
                }
    
                tol_sum+=ma_sum;
            }
    
            printf("%d %d
    ",tol_sum+ma[t][t],tol_step);
    
        }
    
        return 0;
    }
    View Code
    D.
    d.从一些点中找出3个,使围成的三角形面积最小。
    s.才100个点,三重循环。
    ps:用海伦公式wa了,改向量叉乘才过。为啥wa,精度问题?抽空再看看。
    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    
    double X[128];
    double Y[128];
    
    double ff(int i,int j,int k){
        return fabs(X[i]*Y[j]+Y[i]*X[k]+X[j]*Y[k]-X[k]*Y[j]-X[j]*Y[i]-X[i]*Y[k])/2;
    }
    
    int main(){
    
        int T;
        int N;
        int i,j,k;
        double area;
        double mi_area;
    
        scanf("%d",&T);
    
        while(T--){
            scanf("%d",&N);
    
            for(i=0;i<N;++i){
                scanf("%lf%lf",&X[i],&Y[i]);
            }
            area=0;
            mi_area=-1;
            for(i=0;i<N;++i){
                for(j=i+1;j<N;++j){
                    for(k=j+1;k<N;++k){
                        area=ff(i,j,k);
    
                        if(area!=0){
                            if(area<mi_area||mi_area<0){
                                mi_area=area;
                            }
                        }
    
                    }
                }
            }
            if(mi_area<0){
                printf("Impossible
    ");
            }
            else{
                printf("%.2f
    ",mi_area);
            }
        }
    
        return 0;
    }
    View Code
    E.
    s.找规律
    c.张
    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <algorithm>
    #include <string>
    #include <string.h>
    using namespace std;
    #define MAX 500
    #define INF 0x3f3f3f3f
    int mmap[MAX][MAX];
    int nodeMark[MAX];
    #include<iostream>
    #include<stdio.h>
    #include <cmath>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <set>
    #define INF 0x3f3f3f3f
    #define LL long long
    using namespace std;
    int arr[5000005],coun=0;
    
    LL gcd(LL a,LL b){
      LL temp;
      while(a%b!=0){
        temp=a;
        a=b;
        b=temp%b;
      }
      return b;
    }
    
    LL fun(LL a,LL b,LL sum,bool iscir){
      LL tempa=arr[0],tempb=arr[1];
      int xxx=2;
      LL res=0;
      while(tempa<sum && tempb<sum){
        if(tempa>tempb)  res=res+(tempa-tempb)*abs(tempb%a-tempb%b);
        else res=res+(tempb-tempa)*abs(tempa%a-tempa%b);
        tempb<tempa ? tempb=arr[xxx++] : tempa=arr[xxx++];
      }
     // cout<<"*********"<<tempa<<' '<<tempb<<' '<<res<<"******
    "<<endl;
      //if(!iscir) sum++;
      if(tempa<sum)
        res=res+(sum-tempa)*abs(tempa%a-tempa%b);
      if(tempb<sum)
         res=res+(sum-tempb)*abs(tempb%a-tempb%b);
      //cout<<"========"<<res<<"========
    "<<endl;
      return res;
    }
    
    int main(){
      int T;
      LL A,B,N;
      LL res;
      scanf("%d",&T);
      while(T--){
        scanf("%I64d%I64d%I64d",&N,&A,&B);
        res=0;
        if(A==B){
            printf("0
    ");
            continue;
        }
        LL cir=A*B/gcd(A,B);
        LL eend=min(cir,N);
        coun=0;
        for(int i=A;i<=eend;i+=A) arr[coun++]=i;
        for(int i=B;i<eend;i+=B) arr[coun++]=i;
        arr[coun++]=INF;
        sort(arr,arr+coun);
    
        if(cir<N)
          res+=(N/cir*fun(A,B,cir,1));
        res+=fun(A,B,N%cir,0);
    
        //if(N%cir) res--;
        //if(A==1||B==1) A==1 ? res-=(B-1) : res-=(A-1);
        printf("%I64d
    ",res);
      }
    return 0;
    }
    View Code
    F.
     
    G.
    ps:这个题学会了随机数法。。。具体看上篇博客吧。。。尴尬。。
     
    H.
     
    I.
    d.这个题好像是一颗树,可以删除一条边、添加一条边,求最少的操作次数,构成一个单链的环。
    s.方法好像是一个节点的度大于2时,删除它与父节点的边,最后所有的单链再连起来就行了。至于为什么,再看。
     
    J.
    d.一个数c,找出两个质数a、b,使得a-b=c。
    s.当时直接把一些素数打表出来,挨个找,当这些没找到时,认为不存在。
    ps:好像这个是一定存在的,水过因为数据弱吧。。。
    #include<iostream>
    #include<stdio.h>
    #include <cmath>
    #include <algorithm>
    #include <string>
    #include <cstring>
    using namespace std;
    
    #define N 1000000
    bool isprm[N];
    long long xx[N];
    void isprime()
    {
        int i,j,k=0;
        int s,e=sqrt( double(N) )+1;        //sqrt是对于double数开平方
    
        memset(isprm,1,sizeof(isprm));
    
        isprm[0] = isprm[1] = 0;
        for(i=4 ; i < N; i=2+i)
            isprm[i]=0;
    
        for(i=3; i<e; i=2+i)
            if(isprm[i])
                for(s=i*2,j=i*i; j<N; j=j+s)
                    isprm[j]=0;                        //因为j是奇数,所以+奇数后是偶数,不必处理
    }
    
    int main(){
        int coun=0;
        int i;
    
        isprime();
        for(i=0; i<N; i++)
            if(isprm[i]){
                xx[coun++]=i;
            }
    
        int T;
        long long t;
        long long t2;
        bool flag;
    
        scanf("%d",&T);
    
        while(T--){
            scanf("%lld",&t);
    
            flag=false;
            for(i=0;i<coun;++i){
                t2=t+xx[i];
                if(isprm[t2]){
                    flag=true;
                    break;
                }
            }
    
            if(flag){
                printf("%lld %lld
    ",t2,xx[i]);
            }
            else{
                printf("FAIL
    ");
            }
    
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    IDEA中设置自动build-改动代码,不用重启工程,刷新页面即可
    前端上传大文件并支持中途取消上传
    网页上传大文件并支持中途取消上传
    HTTP上传大文件并支持中途取消上传
    B/S上传大文件并支持中途取消上传
    如何将word公式粘贴到CKEditor里面
    如何将word公式粘贴到HTML编辑器里面
    如何将word图片粘贴到HTML编辑器里面
    如何将word图片粘贴到Web编辑器里面
    如何将word公式粘贴到Web编辑器里面
  • 原文地址:https://www.cnblogs.com/gongpixin/p/5452978.html
Copyright © 2011-2022 走看看