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++. ...
随机推荐
- thinkPHP命令执行漏洞
thinkPHP中反斜杠的作用是类库\命名空间 命令执行的姿势 通过反射invokefunction调用call_user_func_array方法,call_user_func_array函数接受两 ...
- DWVA-XSS部分练手闯关
前言 关于XSS基础内容请查看:https://www.cnblogs.com/xhds/p/12239527.html 实验平台采用DWVA v1.10 XSS(Reflected)反射性XSS漏 ...
- 学好Flex布局并不容易
1. Flex布局介绍 CSS的传统布局解决方案,基于盒状模型,依赖display属性.position属性.float属性,对于一些特殊的布局,例如垂直居中,往往要想很多hack的方法来解决. 20 ...
- ABBYY FineReader如何将图片转换为Excel
ABBYY FineReader的OCR文字识别功能很强大,不但可以将文件转换为文本文档或Word文档,也可以识别PDF文件或者图片上的表格,并且转换为Excel文件.下面我就为大家演示一下怎么用AB ...
- CDR中调和工具的使用方法
CDR中的调和工具也是一个神奇的工具,和AI中的混合工具类似,可以做出很多好看的形状,下面先看下他的基本操作方法. 要了解CorelDRAW平面设计软件中的cdr调和工具怎么用,首先要知道调和工具的作 ...
- Eclipse的环境配置
1.想要配置Eclipse的环境,就要先下载Eclipse,并安装它,不会下载安装的小伙伴可以点击下面给的链接,里面有我写的详细的教程,这里就不重复了 Eclipse下载与安装:https://blo ...
- Web 常见漏洞
检测到目标URL存在http host头攻击漏洞 描述:为了方便的获得网站域名,开发人员一般依赖于HTTP Host header.例如,在php里用_SERVER["HTTP_HOST&q ...
- Day 1-决胜IT十八招-前言
走资讯这一行转眼间八年多了,从大学的时候,我有长达十年的时间思索在从事软体开發这一行到底怎麽存活下来,这思考下来,为自己总算找到一个出口来,这十八招只是其一的绝学,见阵这一行干软体开發的变化也很大,从 ...
- 超稳攻略!Rancher 2.3手动轮换证书,保护集群安全!
本文转自Rancher Labs 前 言 Rancher 2.3正式发布已经一年,第一批使用Rancher 2.3的用户可能会遇到Rancher Server证书过期,但是没有自动轮换的情况.这会导致 ...
- centOs7.5.64以上版本的操作系统搭建GitLab记录
一. 安装并配置必要的依赖关系在CentOS系统上安装所需的依赖:ssh,防火墙,postfix(用于邮件通知) ,wget,以下这些命令也会打开系统防火墙中的HTTP和SSH端口访问. 1.安装ss ...