Topcoder 658Div2

本文深入探讨了算法与数据结构的核心概念,从基础的排序算法、动态规划、哈希算法等,到更高级的深度优先搜索、贪心算法、遗传算法等。同时,文章还涵盖了数据结构如二叉树、队列、栈、数组、链表、B树、散列表等的详细解释和应用案例。无论是初学者还是有一定经验的开发者,都能从中获得宝贵的知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

补题风向标——>>

假装题意知道

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;
      }
};

  

正常人类版

 

转载于:https://www.cnblogs.com/forgot93/p/4483278.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值