Codeforces Edu Round 56 A-D
A. Dice Rolling
把\(x\)分解为\(a * 6 + b\),其中\(a\)是满6数,\(b\)满足\(1 <= b < 6\),即可...
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int T; scanf("%d", &T);
while(T--){
int x; scanf("%d", &x);
printf("%d\n", x % 6 ? x / 6 + 1 : x / 6);
}
return 0;
}
B. Letters Rearranging
判断,如果回文就直接调整一位即可。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1010;
char s[N];
int cnt[26], tot = 0, loc = 0;
int main(){
int T; scanf("%d", &T);
while(T--){
memset(cnt, 0, sizeof cnt); loc = tot = 0;
bool ep = false;
scanf("%s", s + 1);
int n = strlen(s + 1);
for(int i = 1; i <= n; i++){
cnt[s[i] - 'a'] ++;
}
for(int i = 0; i < 26; i++){
if(cnt[i]) tot++, loc = i;
}
if(tot == 1) puts("-1");
else{
for(int i = 1; i <= n; i++)
if(s[i] == s[n - i + 1] && i != n - i + 1){
for(int j = 1; j <= n; j++){
if(i != j && j != n - i + 1){
if(s[j] != s[i]){
swap(s[j], s[i]);
printf("%s\n", s + 1);
ep = true; break;
}
}
}
if(ep) break;
}
if(!ep) printf("%s\n", s + 1);
}
}
return 0;
}
C. Mishka and the Last Exam
贪心构造,尽量使每个\(a[i] (1 <= i <= n / 2)\)最小:
在符合\(a[i - 1] <= a[i]\)的条件下,也要满足\(a[n - i + 1] <= a[n - i + 1 + 1]\),所以说这个界限为:
\(a[i] = max(a[i - 1], b[i] - a[n - i + 1 + 1])\) 注意边界,把\(a[n + 1]\) 赋值为极大值。
#include <iostream>
#include <cstdio>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N = 200010;
int n;
LL a[N], b[N >> 1];
int main(){
scanf("%d", &n);
a[n + 1] = 9223372036854775807ll;
for(int i = 1; i <= (n >> 1); i++) {
scanf("%lld", b + i);
a[i] = max(a[i - 1], b[i] - a[n - i + 1 + 1]);
a[n - i + 1] = b[i] - a[i];
}
for(int i = 1; i <= n; i++)
printf("%lld ", a[i]);
return 0;
}
D. Beautiful Graph
实质是一个二分图染色问题,对于选定每个奇数后,偶数是对应主线的,所以只需算奇数的方案即可。
对于每一个联通快而言相互没有影响,它们的方案是:
\(2 ^ {cnt0} + 2 ^ {cnt1}\)其中两个\(cnt\)代表二分图染色两个色彩的数量,颜色可以调换,且填奇数,每个位置有两种选择...
答案就是每个联通快的相乘,注意如果二分图失败了就\(ans = 0\)吧
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
const int N = 300010, M = 300010, MOD = 998244353;
int n, m, numE, head[N], f[N], ans;
struct Edge{
int next, to;
}e[M << 1];
void addEdge(int from, int to){
e[++numE].next = head[from];
e[numE].to = to;
head[from] = numE;
}
queue<int> q;
int power(int a, int b){
int res = 1;
while(b){
if(b & 1) res = (LL)res * a % MOD;
a = (LL)a * a % MOD;
b >>= 1;
}
return res;
}
int main(){
int T; scanf("%d", &T);
while(T--){
while(q.size()) q.pop();
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) head[i] = 0, f[i] = -1;
numE = 0; ans = 1;
for(int i = 1; i <= m; i++){
int u, v; scanf("%d%d", &u, &v);
addEdge(u, v); addEdge(v, u);
}
for(int i = 1; i <= n; i++){
if(~f[i]) continue;
int cnt0 = 1, cnt1 = 0;
f[i] = 0; q.push(i);
while(!q.empty()){
int u = q.front(); q.pop();
for(int i = head[u]; i; i = e[i].next){
int v = e[i].to;
if(f[v] == -1){
f[v] = f[u] ^ 1;
if(!f[v]) cnt0++;
else cnt1++;
q.push(v);
}else if(f[v] != (f[u] ^ 1)){
ans = 0; break;
}
}
if(!ans) break;
}
if(!ans) break;
ans = (ans * ((LL)(power(2, cnt0) + power(2, cnt1)) % MOD)) % MOD;
}
printf("%d\n", ans);
}
return 0;
}
Codeforces Edu Round 56 A-D的更多相关文章
- Codeforces Beta Round #56 A. Where Are My Flakes? —— 贪心
题目链接:http://codeforces.com/problemset/problem/60/A A. Where Are My Flakes? time limit per test 2 sec ...
- Codeforces Beta Round #52 (Div. 2)
Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- Ceph部署mon出现0.0.0.0地址
前言 最近在群里两次看到出现mon地址不对的问题,都是显示0.0.0.0:0地址,如下所示: [root@lab8106 ceph]# ceph -s cluster 3137d009-e41e-41 ...
- vue+node+mysql
准备工作 安装node,这是必须的 新版node自带npm,安装Node.js时会一起安装,npm的作用就是对Node.js依赖的包进行管理,也可以理解为用来安装/卸载Node.js需要装的东西.验证 ...
- mysql 数据库存储路径更改
使用了VPS一段时间之后发现磁盘空间快满了.本人的VPS在购买的时候买了500gb的磁盘,提供商赠送了20GB的高性能系统磁盘.这样系统就有两个磁盘空间了.在初次安装mysql 的时候将数据库目录安装 ...
- 洛谷 P2101 命运石之门的选择 (分治)
P2101 命运石之门的选择 (分治) 介绍 El Psy Congroo 题目链接 没错,作为石头门厨,怎么能不做石头门的题呢?(在搜石头门的时 候搜到了本题) 本题作为一道分治基础练习题还是不错的 ...
- centos 6 系统下同步本地时间
1.date显示系统时间 [root@oldboy ~]# dateTue Mar 31 22:45:55 CST 2020 #CST是指是指某中标准时间 非东八区时间 更改时间的三种方法 1.c ...
- CA证书与https讲解
最近面试问到这个问题,之前了解过但答的不是很好,再补充补充一下https方面的知识. 备注:以下非原创文章. CA证书与https讲解 1.什么是CA证书. ◇ 普通的介绍信 想必大伙儿都听说过介绍信 ...
- 如何用Prometheus监控十万container的Kubernetes集群
概述 不久前,我们在文章<如何扩展单个Prometheus实现近万Kubernetes集群监控?>中详细介绍了TKE团队大规模Kubernetes联邦监控系统Kvass的演进过程,其中介绍 ...
- 循序渐进VUE+Element 前端应用开发(29)--- 高级查询条件的界面设计
在系统模块中的业务列表展示里面,一般我们都会在列表中放置一些查询条件,如果是表字段不多,大多数情况下,放置的条件有十个八个就可以了,如果是字段很多,而这些条件信息也很关键的时候,就可能放置很多条件,但 ...
- leetcode151. 翻转字符串里的单词
给定一个字符串,逐个翻转字符串中的每个单词. 示例 1:输入: "the sky is blue"输出: "blue is sky the"示例 2:输入: & ...
- springboot打jar包将引用的第三方包、配置文件(.properties、.xml)、静态资源打在包外
1.外置配置文件 Springboot读取核心配置文件(.properties)的外部配置文件调用方式为 jar包当前目录下的/config目录 因此要外置配置文件就在jar所在目录新建config文 ...