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的更多相关文章

  1. 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 ...

  2. Codeforces Beta Round #52 (Div. 2)

    Codeforces Beta Round #52 (Div. 2) http://codeforces.com/contest/56 A #include<bits/stdc++.h> ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. 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]中有多少个数 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. POSIX信号量与互斥锁实现生产者消费者模型

    posix信号量 Link with -lpthread. sem_t *sem_open(const char *name, int oflag);//打开POSIX信号量 sem_t *sem_o ...

  2. makefile 函数

    1. findstring $(findstring <find>, <in>) 从 in 中查找 find ,如果找到则返回find,否则返回空 str1=1111 str2 ...

  3. .net core中的哪些过滤器 (Authorization篇)

    前言 咱们上篇说到,过滤的简单介绍,但是未介绍如何使用,接下来几篇,我来给大家讲讲如何使用,今天第一篇是Authorization.认证过滤器, 开发环境介绍 开发工具:VS2019 开发环境:.ne ...

  4. mysql 数据库存储路径更改

    使用了VPS一段时间之后发现磁盘空间快满了.本人的VPS在购买的时候买了500gb的磁盘,提供商赠送了20GB的高性能系统磁盘.这样系统就有两个磁盘空间了.在初次安装mysql 的时候将数据库目录安装 ...

  5. webpack : 无法加载文件 C:\Users\Eileen\AppData\Roaming\npm\webpack.ps1,因为在此系统上禁止运行脚本

    报错内容: webpack : 无法加载文件 C:\Users\Eileen\AppData\Roaming\npm\webpack.ps1,因为在此系统上禁止运行脚本.有关详细信息,请参阅 http ...

  6. 精尽MyBatis源码分析 - MyBatis初始化(二)之加载Mapper接口与XML映射文件

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  7. wireshark实战应用(长期更新,工作随笔)

    Wireshark检索语法 过滤IP地址 ip.addr eq 192.168.1.1 ip.addr == 192.168.1.1 //过滤源IP地址 ip.src eq 192.168.1.1 i ...

  8. js替换div里的内容

    <!DOCTYPE html><html><head><meta charset="utf-8"><title>< ...

  9. 一文带你读懂!华为云在ACMUG技术沙龙上都透露了些啥?

    摘要:近日,华为云数据库业务总裁苏光牛在ACMUG中国MySQL用户组主办的 "华为云专场" 技术沙龙中分享了华为云数据库重磅新品GaussDB的核心能力与竞争优势.那么, Gau ...

  10. 面试阿里,字节,美团必看的Spring的Bean管理详解

    IOC容器 工厂只负责创建对象,而Spring当然不仅仅是一个对象工厂,其核心是一个对象容器,其具备控制反转的能力,所以也称为IOC容器. 帮助我们存放对象,并且管理对象,包括:创建.销毁.装配,这样 ...