首页 > 其他分享 >B - Coloring Matrix

B - Coloring Matrix

时间:2023-04-16 16:56:24浏览次数:23  
标签:typedef Coloring Matrix int void maxn include string

B - Coloring Matrix

https://atcoder.jp/contests/abc298/tasks/abc298_b

 

思路

判断A矩阵是否满足条件,

不符合,对A矩阵逆时针旋转, 旋转后对A矩阵继续判断,

直到满足条件,或者A矩阵复位。

 

Code

#include <iomanip>
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <limits.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#ifdef TESTING
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif

#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)

/******************************** COMMON FUNC START ***************************************/

LL quick_pow(LL x,LL n,LL m){
    LL res = 1;
    while(n > 0){
        if(n & 1)    res = res * x % m;
        x = x * x % m;
        n >>= 1;//相当于n=n/2.详情请参考位移运算符。
    }

    return res;
}

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
        s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
        s[i] = s[i] - 'A' + 'a';
    return s;
}

inline void OPEN(string s)
{
#ifndef TESTING
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
#endif
}

/******************************** COMMON FUNC END ***************************************/

/******************************** GRAPH START ***************************************/
// Graph class represents a directed graph
// using adjacency list representation
class Graph {
public:
    map<int, bool> visited;
    map<int, list<int> > adj;

    // function to add an edge to graph
    void addEdge(int v, int w);

    // DFS traversal of the vertices
    // reachable from v
    void DFS(int v);
};

void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w); // Add w to v’s list.
}

void Graph::DFS(int v)
{
    // Mark the current node as visited and
    // print it
    visited[v] = true;
    cout << v << " ";

    // Recur for all the vertices adjacent
    // to this vertex
    list<int>::iterator i;
    for (i = adj[v].begin(); i != adj[v].end(); ++i)
        if (!visited[*i])
            DFS(*i);
}

/******************************** GRAPH END ***************************************/

/*
https://atcoder.jp/contests/abcxxx/tasks/abcxxx_d
*/

const int maxn = 102;

int n;
int a[maxn][maxn], atemp[maxn][maxn];
int b[maxn][maxn];

void print(){
    cout << "-------------" << endl;
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            cout << a[i][j] << " ";
        }
        
        cout << endl;
    }
}

void rotate(){
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            atemp[n+1-j][i] = a[i][j];
        }
    }

    memcpy(a, atemp, sizeof(a));
}

bool compare(){
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            if (a[i][j] == 1){
                if (1 != b[i][j]){
                    return false;
                }
            }
        }
    }

    return true;
}

int main()
{
    cin >> n;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            int temp;
            cin >> temp;
            a[i][j] = temp;
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            int temp;
            cin >> temp;
            b[i][j] = temp;
        }
    }

    for(int i=0; i<4; i++){
        if (compare()){
            cout << "Yes" << endl;
            return 0;
        }
        
        
//        print();
        
        rotate();
        
//        print();
    }

    cout << "No" << endl;

    return 0;
}

 

标签:typedef,Coloring,Matrix,int,void,maxn,include,string
From: https://www.cnblogs.com/lightsong/p/17323541.html

相关文章

  • HDU 4313 Matrix (贪心)
    题目地址:HDU4313利用最小生成树的思想,这里是从大往下删,能删则删,不能删就留着。用个并查集维护下。代码如下:#include<iostream>#include<string.h>#include<math.h>#include<queue>#include<algorithm>#include<stdlib.h>#include<map>#include<set>......
  • R语言中的matrix(矩阵),list(列表),data.frame(数据框)总结
    一、R语言中的矩阵matrix是一个二维的数组array,因此数组array的一些操作它也适用。①它与array相比,特有的是矩阵的一些运算,例如:求维度:dim(A)转置:t(A)求行列式:det(A)矩阵相乘:x%*%y对角运算:diag(A)求逆:solve(A,b)求特征值和特征向量:eigen(A)奇异值分解:svd(A)②在多维数组中,apply函数......
  • UVa 10004 Bicoloring (DFS&二分图)
    10004-BicoloringTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945In1976the``FourColorMapTheorem"wasprovenwiththeassistanceofacomput......
  • 【spring学习笔记】(二)Spring MVC注解配置 参数转换注解@RequestMapping@RequestParam
    @TOC介绍在SpringMVC项目中,<\context:component-scan>配置标签还会开启@Request-Mapping、@GetMapping等映射注解功能(也就是会注册RequestMappingHandler-Mapping和RequestMappingHandlerAdapter等请求映射和处理等组件),但是<context:component-scan>不支持数据转换或验证等注解功......
  • Vulnhub之Matrix Breakout 2 Morpheus靶机详细测试过程
    MatrixBreakout:2Morpheus靶机信息名称:Matrix-Breakout:2Morpheus地址:https://www.vulnhub.com/entry/matrix-breakout-2-morpheus,757/虽然作者提示该靶机最好是在VirtualBox部署,但是经过测试,本靶机在VirtualBox无法启动,更适合导入到Vmware中。识别目标主机IP地址(ka......
  • CodeForces - 149D Coloring Brackets(区间DP)
    题目大意:给你一个符合括号规则的字符串,现在要求你将这些括号染色,染色规则如下1.一个括号要么被染成红色,要么被染成蓝色,要么不染2.相邻的括号的颜色不能相同(可以同为无色)3.成对的括号只能有一个被染色问染色的方案数解题思路:0表示不染,1表示红色,2表示蓝色那么成对的括号......
  • c++实现Matlab矩阵Matrix类(实矩阵Matrix、复矩阵CMatrix)
    全栈工程师开发手册(作者:栾鹏)matlab2c动态链接库下载matlab库函数大全matlab2c基础教程matlab2c开发全解教程开发注意事项:1、目前matlab2c对矩阵的实现仅包含实数型、复数型数据。实数型矩阵使用Matrix定义,复数型矩阵使用CMatrix定义。2、实数矩阵元素int、float元素类型会自动......
  • WebMatrix3 启动报KeyNotFoundException错误解决方法
    我上网下载了WebMatrix3、iisexpress8安装以后运行WebMatrix3报错,日志如下:System.Collections.Generic.KeyNotFoundException:要使用的命令不在有效命令列表中。Thecommandbeingusedisnotinthelistofvalidcommands.应用程序:WebMatrix.exeFramework版本:v4.0.3......
  • [Algorithm] Dynamic programming - 01 - Drawing 2-d matrix
    Problem:LevenshteinDistanceWriteafunctionthattakesintwostringsandreturnstheminimumnumberofeditoperationsthatneedtobeperformedonthefir......
  • [ABC294Ex] K-Coloring
    考虑dfs后搞出dfs树,考虑若干返祖边有限制,那么,我们一个朴素的想法是枚举这些有被返祖边搞到的点的颜色,但这样最坏是\(O(K^n)\)的。但显然一条返祖边在钦定完一个端点......