zoukankan      html  css  js  c++  java
  • 洛谷 八连测 R4

    T1

    按题意判断,每次直接输出即可。(莫名输入AFO)

    #include <stdio.h>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <vector>
    using namespace std;
    int main()
    {
      char c=getchar();int f=1;
      while(c!='
    ')
      {
          if((c>='a'&&c<='z')&&f)c-=32,f=0;
          else if(c>='A'&&c<='Z'&&f)f=0;
          else if((c>='A'&&c<='Z')&&!f)c+=32;
        printf("%c",c); 
        if(c=='.')f=1;
        c=getchar();
      }
      return 0;
    }
    View Code

    T2

    链表

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <memory.h>
    
    using namespace std;
    const int maxn = 100005;
    
    int pos[maxn],n,a[maxn];
    namespace ST {
        #define ls rt<<1
        #define rs rt<<1|1
        int mx[maxn<<2];
        void build(int rt,int L,int R) {
            if (L>=R) {
                mx[rt]=a[L];return ;
            }
            int mid=L+R>>1;
            build(ls,L,mid);
            build(rs,mid+1,R);
            mx[rt]=max(mx[ls],mx[rs]);
        }
        void assign0(int rt,int L,int R,int p) {
            if (L>=R) {
                mx[rt]=0;return ;
            }
            int mid=L+R>>1;
            if (p<=mid) assign0(ls,L,mid,p);
            else assign0(rs,mid+1,R,p);
            mx[rt]=max(mx[ls],mx[rs]);
        }
        int findl(int rt,int L,int R,int l) {
            if (!mx[rt]) return 0;
            if (l>R) return 0;
            if (L>=R) return L;
            int mid=L+R>>1,res;
            if (l<=mid&&(res=findl(ls,L,mid,l))) return res;
            return findl(rs,mid+1,R,l);
        }
        int findmx(int rt,int L,int R,int l,int r) {
            if (L>=l&&R<=r) return mx[rt];
            int mid=L+R>>1,res=0;
            if (l<=mid) res=max(res,findmx(ls,L,mid,l,r));
            if (r>mid) res=max(res,findmx(rs,mid+1,R,l,r));
            return res;
        }
    }
    using namespace ST;
    
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("wa.in","r",stdin);
            freopen("wa.out","w",stdout);
        #endif
        scanf("%d",&n);
        for (int i=1;i<=n;i++)
            scanf("%d",&a[i]),pos[a[i]]=i;
        build(1,1,n);
        for (int i=1;i<=n>>1;i++)
        {
            int p=pos[mx[1]],q=findl(1,1,n,p+1);
            if (!q) p=pos[findmx(1,1,n,1,p-1)],q=findl(1,1,n,p+1);
            assign0(1,1,n,p);assign0(1,1,n,q);
            printf("%d %d ",a[p],a[q]);
        }
        return 0;
    }
    View Code

    T3

    暴力dfs(???!!!)

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <memory.h>
    #include <string.h>
    
    using namespace std;
    
    const int maxn = 15;
    const int inf = 1<<20;
    
    int a[maxn][maxn],ans,n,m,d[maxn],c[maxn][3];
    int check(int o) {
        return o<=12&&(o%3==0?1:0);
    }
    void dfs(int stp) {
        if (stp>n) {
            int res=0;
            for (int j=1;j<=m;j++)
            {
                c[j][1]=c[j][2]=c[j][0]=0;
                for (int i=1;i<=n;i++)
                for (int k=0;k<=2;k++)
                    c[j][k]+=check(d[i]+a[i][j]+k);
                res+=max(max(c[j][0],c[j][1]),c[j][2]);
            }
            ans=max(ans,res);
            return ;
        }
        for (int i=0;i<=2;i++)
            d[stp]=i,dfs(stp+1);
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
            freopen("haji.in","r",stdin);
            freopen("haji.out","w",stdout);
        #endif
        scanf("%d %d",&n,&m);
        for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
        dfs(1);printf("%d",ans);
        return 0;
    }
    View Code
  • 相关阅读:
    数组系列教材 (二)- Java 如何初始化数组
    数组系列教材 (一)- Java 如何创建一个数组
    数组系列教材 (一)- Java 如何创建一个数组
    JAVA 面试题
    JAVA 面试题
    JAVA 面试题
    HelloWorld系列(五)- 在Eclipse中运行第一个 java 程序
    [LeetCode] 142. Linked List Cycle II
    [LeetCode] 141. Linked List Cycle
    [LeetCode] 82. Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/new-hand/p/7719712.html
Copyright © 2011-2022 走看看