zoukankan      html  css  js  c++  java
  • Topcoder 658Div2

    补题风向标——>>

    假装题意知道

    A:暴力合成一遍了

    n=s.size();

    m=t.size();

    ss+=s;

    tt+=t;

    if (ss==tt) or not;

    B:题意是给定 1个或者2个或者3个,先假设3个数啊:a,b,c;

           每次你能a-9,b-3,c-1 类似如此过程,求最小操作数。DIV 1 650是加强版 数的个数<=50;

    只会最暴力,然后DP数组保存状态,已经都最暴力了,所以不用想很多了

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    #include<string.h>
    #include<string>
    #include<iostream>
    #include<vector>
    
    using namespace std;
    
    
    int a[123];
    int dp[66][66][66];
    int n;
    
    int dfs(int x,int y,int z)
    {
            if (x<=0&&y<=0&&z<=0) return 0;
            if (dp[x][y][z]) return dp[x][y][z];
            int mx=1234;
            mx=min(mx,dfs(max(0,x-1),max(0,y-3),max(0,z-9)));
            mx=min(mx,dfs(max(0,x-1),max(0,y-9),max(0,z-3)));
            mx=min(mx,dfs(max(0,x-3),max(0,y-1),max(0,z-9)));
            mx=min(mx,dfs(max(0,x-3),max(0,y-9),max(0,z-1)));
            mx=min(mx,dfs(max(0,x-9),max(0,y-3),max(0,z-1)));
            mx=min(mx,dfs(max(0,x-9),max(0,y-1),max(0,z-3)));
        return dp[x][y][z]=mx+1;
    }
    class  MutaliskEasy
    {
         public:
         int minimalAttacks(vector <int> x)
         {
            n=x.size();
            memset(dp,0,sizeof(dp));
            sort(x.begin(),x.end());
            for (int i=0;i<n;i++) a[i]=x[i];
            int ans=0;
            if (n==1) return (a[0]+8)/9;
            if (n==2) a[2]=0;
    
            return dfs(a[0],a[1],a[2]);
         }
    };
    
    int main()
    {   int n;
        vector<int> q;
        cin>>n;
        for (int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            q.push_back(x);
        }
        MutaliskEasy p;
        cout<<p.minimalAttacks(q);
        return 0;
    
    }
    

     C: 是DIV1 A 

       题目很炫酷啦;

    给一颗树 X[I][J]=='O',表示I,J 长度为奇数,X[I][J]=='E' 表是为偶数 ‘?’ 不确定  

    先来第一份,类似floyd dp 找,我们知道奇数+偶数=奇数,其他全为偶数。

    我们先判断 是否不满足答案 输出-1;

    然后构造:0 到其他点 为奇数 连一条边,

                  0到Y Y到其他边 再连一条边,0->y 是奇书,0->其他边为偶数

    虽然说得很容统,不过确实不会 ,想了很久,脑洞大。。

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    #include <fstream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <map>
    #include <deque>
    #include <set>
    
    using namespace std;
    
    
    
    /*
    
    int dfs(int v,int w)
    {
        c[v]=w;
        for (int i=0;i<n;i++)
        {
            if (x[v][i]=='E'&&x[i][v]=='O') return 0;
            if (x[v][i]=='O'&&x[i][v]=='E') return 0;
    
            if (x[v][i]=='E'||x[i][v]=='E')
            {
                if (c[i]==0)
                {
                    if (dfs(i,w)==0) return 0;
                }
                else if (w!=c[i]) return 0;
            }
            else if (x[v][i]=='O'||x[i][v]=='O')
            {
                if (c[i]==0)
                {
                    if (dfs(i,w==1?2:1)==0) return 0;
                }
                else if (w==c[i]) return 0;
            }
        }
        return 1;
    }
    */
    int a[60][60];
    
    class OddEvenTree{
    public:
         vector<int> getTree(vector <string> x){
         int n=x[0].size();
          
          for (int i=0;i<n;i++)
          for (int j=0;j<n;j++)
          if (x[i][j]=='O') a[i][j]=1;
        
             vector<int> t;
             t.push_back(-1);
             for (int k=0;k<n;k++)
             for (int i=0;i<n;i++)
             for (int j=0;j<n;j++)
             if ((a[i][k]+a[k][j])%2!=a[i][j]) return t;
    
              vector<int>res;
              int y=-1;
              for (int i=1;i<n;i++)
              if (a[0][i])
              {
                  res.push_back(0);
                  res.push_back(i);
                  y=i;
              }
    
              if (y==-1) return t;
              for (int i=1;i<n;i++)
              if (!a[0][i])
              {
                  res.push_back(y);
                  res.push_back(i);
              }
              return res;
          }
    };
    

     DFS版。。

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    #include <fstream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <map>
    #include <deque>
    #include <set>
    
    using namespace std;
    
    
    
    /*
    
    int dfs(int v,int w)
    {
        c[v]=w;
        for (int i=0;i<n;i++)
        {
            if (x[v][i]=='E'&&x[i][v]=='O') return 0;
            if (x[v][i]=='O'&&x[i][v]=='E') return 0;
    
            if (x[v][i]=='E'||x[i][v]=='E')
            {
                if (c[i]==0)
                {
                    if (dfs(i,w)==0) return 0;
                }
                else if (w!=c[i]) return 0;
            }
            else if (x[v][i]=='O'||x[i][v]=='O')
            {
                if (c[i]==0)
                {
                    if (dfs(i,w==1?2:1)==0) return 0;
                }
                else if (w==c[i]) return 0;
            }
        }
        return 1;
    }
    */
    int a[60][60];
    
    class OddEvenTree{
    public:
         vector<int> getTree(vector <string> x){
         int n=x[0].size();
          
          for (int i=0;i<n;i++)
          for (int j=0;j<n;j++)
          if (x[i][j]=='O') a[i][j]=1;
        
             vector<int> t;
             t.push_back(-1);
             for (int k=0;k<n;k++)
             for (int i=0;i<n;i++)
             for (int j=0;j<n;j++)
             if ((a[i][k]+a[k][j])%2!=a[i][j]) return t;
    
              vector<int>res;
              int y=-1;
              for (int i=1;i<n;i++)
              if (a[0][i])
              {
                  res.push_back(0);
                  res.push_back(i);
                  y=i;
              }
    
              if (y==-1) return t;
              for (int i=1;i<n;i++)
              if (!a[0][i])
              {
                  res.push_back(y);
                  res.push_back(i);
              }
              return res;
          }
    };
    

      

    正常人类版

  • 相关阅读:
    C# 数据权限缓存
    .net core平台使用遇到的坑
    @RenderBody @RenderPage @RenderSection
    _ViewStart.cshtml介绍
    Git中的AutoCRLF与SafeCRLF换行符问题
    select fotr update
    索引的区分度
    索引最左匹配原则
    mysql索引相关知识
    锁-乐观锁和悲观锁
  • 原文地址:https://www.cnblogs.com/forgot93/p/4483278.html
Copyright © 2011-2022 走看看