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. C++如何实现多态

    1.   什么是多态多态是C++中的一个重要的基础,面向对象编程语言中,接口的多种不同的实现方式即为多态.2.   多态带来的好处多态带来两个明显的好处:一是不用记大量的函数名了,二是它会依据调用时的 ...

  2. bluestore对象挂载到系统进行提取

    前言 之前在filestore里面,pg是直接暴露到文件系统的,也就是可以直接进去查看或者拷贝,在极端情况下,多个osd无法启动,pg无法导出的时候,那么对pg内部对象的操作处理,是可以作为最后恢复数 ...

  3. HotSpot源码分析之类模型

    HotSpot采用了OOP-Klass模型描述Java的类和对象.Klass模型采用Klass类及相关子类的对象来描述具体的Java类.一般HotSpot JVM 在加载Java的Class 文件时, ...

  4. C#高级编程之泛型一(泛型的引入、泛型的使用、何为泛型)

    为何引入泛型 当我们要对不同类型的参数执行类似的方法时:如下所示功能打印传入参数的相关信息. class CommonMethdod { /// <summary> /// show in ...

  5. FL Studio采样器设置的功能是什么

    FL Studio是一款很集成化的软件,它和很多其他的软件不同,FL Studio的通道中集成了很多采样器.这种整合的方式不但功能强大而且也很便捷.今天小编就来为大家详细的简介下FL Studio采样 ...

  6. 二 HTML文档基本结构

    2.1 HTML5文档结构: HTML5文档结构包括头部(head).主体(body)两大部分. 2.1.1<!DOCTYPE>声明 引用官方的DTD文件,在HTML5之前版本,如xHTM ...

  7. 通过城市联动实时将地址显示到text中

    <div class="form-group field-supplier-sort <?php if($model->getErrors('province_id') | ...

  8. 关于Linux虚拟机连接不上网络的问题

    前阵子自学Linux(版本是CentOS6 -VMware ),因为连不上网的问题搁置了一段时间,昨天又重新拾起来,花了一下午时间终于搞定.下面说几点,给自己学习历程一个记录,也希望能帮到其他初学者. ...

  9. 编程小白必备——主流语言C语言知识点

    对于编程语言来说,经常看到有因为各自支持的语言阵营而互怼的,其实根本没那个必要,都只是一种工具而已.当多数主流语言都会使用时也许你就不会有偏见了,本质不过都是用来描述计算机的一个任务,只是每门语言设计 ...

  10. 深度阅读:大学生课外知识补充,这些课堂上不教的 C++ 的基本特性你都知道吗?

    来源:知乎 王师傅的专栏 C++ 作为一个历史久远,功能丰(yong)富(zhong)而且标准与时俱进的语言,理应什么都能做,什么都用得起来.不过日常使用中我们初学者真的好像只学到了其中的一部分,对于 ...