codeforce 623 A

2023-10-28 08:18
文章标签 623 codeforce

本文主要是介绍codeforce 623 A,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!



因为只有a b c , b 和其他都联通, 从这里突破


#include <bits/stdc++.h>
using namespace std ;typedef long long ll ;
const int inf = 0x3f3f3f3f ;
const int maxn = 550 ;
bool g[maxn][maxn] ;
int deg[maxn] ;
bool vis[maxn] ;
char ans[maxn] ;
bool check(char a , char b){int x = a - 'a' , y = b - 'a' ;if( fabs(x - y) <= 1 ) return true ;return false ;
}
bool CHECK(int n){for(int i = 1 ; i <= n ; i ++ ){for(int j = i + 1 ; j <= n ; j ++ ){if((check(ans[i] , ans[j]) && g[i][j] == 1) || (!check(ans[i] , ans[j]) && !g[i][j]))continue ;else{return false ;}}}return true ;
}
int main(){int n , m , a , b;scanf("%d %d" , &n , &m) ;memset(g , 0 , sizeof(g)) ;memset(deg , 0 , sizeof(deg)) ;memset(vis , 0 , sizeof(vis)) ;for(int i = 0 ; i < m ; i ++ ){scanf("%d %d" , &a , &b) ;deg[a] ++ , deg[b] ++ ;g[a][b] = g[b][a] = 1 ;}for(int i = 1 ; i <= n ; i ++ ){if(deg[i] == n - 1){vis[i] = 1 ;ans[i] = 'b' ;}}for(int i = 1 ; i <= n ; i ++ ){if(!vis[i]){vis[i] = 1 ;ans[i] = 'a' ;for(int j = 1 ; j <= n ; j ++ ){if(vis[j] || g[i][j] == 0) continue ;vis[j] = 1 ;ans[j] = 'a' ;}break ;}}for(int i = 1 ; i <= n ; i ++ ){if(!vis[i]) ans[i] = 'c' ;}//puts(ans + 1) ;//if(m == 95) for(int i = 1 ; i <= n ; i ++ ) printf("%c" , ans[i]) ;if(CHECK(n)) { puts("Yes") ; puts(ans + 1) ; }else puts("No") ;return 0 ;
}

这篇关于codeforce 623 A的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/291904

相关文章

codeforce 9C(Hexadecimal's Numbers)

来   看谁的代码短 C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output One beautiful July morning

codeforce 7C 拓展欧几里得 详解

比如说  ax+by=gcd(a,b) 假设  excgcd(int a,int  b,int&x,int&y)是求解这个方程的函数 其返回值是gcd(a,b)(ps: a和b的最大公因子) 假设我们已经求得了b*x1+(a%b)*y1=gcd(a,b); x1 ,y1即为其解 又有  a%b=a-(a/b)*b; 带入得 a*y1+b*(x1-(a/b))=gcd(a,b); 而

Codeforce 963

CF 963 B 模拟加贪心 偶数个数C 模拟+前缀和 灯能否全亮D 二分+DP 中位数尽可能大F1 模拟+镜像 题目链接 B 模拟加贪心 偶数个数 考点:贪心 思路:除了全是偶数的情况,其他的情况都需要将偶数转换为奇数。最少的操作步数是偶数个数,如果有一步操作执行之前最小的偶数都比最大的奇数大,则操作步数要加1,即最后结果是偶数个数+1. 代码1: t = int(

Codeforce 214 Div 2 B.Hometask

题目描述: Description Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a

codeforce

http://codeforces.com/problemset/submit 学号  杭电密码

CodeForce #429 DIV2 A B C题解

A:http://codeforces.com/contest/841/problem/A 题意:n个气球分给k个人,是否有这样的解:每个人手里的气球都颜色不重复 思路:个数最多的颜色个球的个数 >k, 就必然有人手里两个球 #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>usin

topcoder srm 623解题报告

详见:http://robotcator.logdown.com/posts/231132-topcoder-srm-623 推荐使用插件greed 2.0,非常使用的插件。但我不知道如何自己添加测试数据,下次再学习下。 Greed 2.0 https://github.com/shivawu/topcoder-greed 250pt 题意:环形跑道上有n棵树,标号为1--n,Alice跑

光纤网络电力控制系统设计方案:623-6U CPCI的光纤网络电力控制系统

6U CPCI的光纤网络电力控制系统   一、设备概述       柔性直流输电系统中用于控制与测量的FS系统,适用于风电和太阳能发电的并网快速数值计算和闭环控制,以及与直流输电系统的换流器有关的特殊控制功能,包括门控单元的信号处理。该控制板的最大响应周期为1us,可以适应以后风力和太阳直流输电工程的特殊应用。       该控制系统,同时也可以柔性直流阀进行控制使用。

CodeForce[1500-2000]——1950E Nearly Shortest Repeating Substring

codeforces刷题日记 题目大意:给你一个长度为n的字符串s,要寻找一个长度最小的字符串k,能够让字符串k进行1或多次的拼接,让拼接成的字符串和字符串s长度相等,且至多一个字母不一样。求k的最小长度。 思路:从1到n遍历k的长度i,如果i整除,就跳过,这时s被分成了n/i段,取出第一段和最后一段。如果这两段相等,那其他段必定和这两段一样(不一样的值字母允许存在一个),才符合条件。要是

【优化算法】白鲨优化算法(WSO)【含Matlab源码 623期】

⛄一、获取代码方式 获取代码方式1: 完整代码已上传我的资源:【优化算法】白鲨优化算法(WSO)【含Matlab源码 623期】 获取代码方式2: 付费专栏Matlab优化求解(初级版) 备注: 点击上面蓝色字体付费专栏Matlab优化求解(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab优化求解(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资