题目链接https://codeforces.com/contest/1093

A. Dice Rolling

题意:

有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次,能使扔出的总和等于xi。

题解:

由于是special judge,模拟一下搞搞就行了= =

代码如下:

#include <bits/stdc++.h>
using namespace std; int main(){
int t;
cin>>t;
int n;
while(t--){
cin>>n;
for(int i=;i<=;i++){
if(n%i!=){
cout<<n/i+(n%i!=)<<endl;
break ;
}
}
}
return ;
}

B. Letters Rearranging

题意:

给出一个字符串,现在你可以任意交换字符位置,然后输出一种非回文串的方案,如果没有这样一种方案,输出-1。

题解:

注意回文串的性质,那么我们首先判断一下所有字符是否相同,如若相同直接输出-1。否则排个序就好了~

代码如下:

#include <bits/stdc++.h>
using namespace std;
int t;
const int N = ;
char s[N];
int main(){
cin>>t;
while(t--){
scanf("%s",s);
int flag = ;
int len =strlen(s);
s[len]=s[];
for(int i=;i<=len;i++){
if(s[i]!=s[]) flag=;
}
if(flag) cout<<-<<endl;
else{
sort(s,s+len);
for(int i=;i<len;i++) cout<<s[i];
cout<<endl;
}
}
return ;
}

C. Mishka and the Last Exam

题意:

一共有n个数,现在给出b1,b2....bn/2,满足bi=ai+an-i+1。

现在要你构造出合法的a1....an,并且a1<=a2<=...<=an,保证输入有解。

题解:

对于b1=a1+an来说,我们让a1=0,a2=b1是最好的,这样可以让左右端点最大。

对于后面的每个bi,我们令d=bi-bi-1,那么如若d>0,我们可以想,假若a2,an-1不变,那么他们之和是小于b2的,所以我们就让左端点变大(贪心策略)。

对于d=0或者d<=0都可以同样的策略去想(因为题目保证输入有解)。

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e5+;
int n;
ll a[N],b[N];
int main(){
cin>>n;
for(int i=;i<=n/;i++) cin>>b[i];
a[]=;a[n]=b[];
for(int i=;i<=n/;i++){
ll d = b[i]-b[i-];
if(d>=) a[i]=d+a[i-],a[n-i+]=a[n-i+];
else a[i]=a[i-],a[n-i+]=a[n-i+]+d;
}
for(int i=;i<=n;i++) cout<<a[i]<<" ";
return ;
}

D. Beautiful Graph

题意:

给出一个图,有n个点,m条边,每个点都有权值1,2或3。现在要你给点权赋值,满足相邻的两个点和为奇数。问一共有多少情况,注意这个图不一定保证连通。

题解:

根据题意我们知道,相邻的两个点必然为一奇一偶,所以我们可以用二分图染色来判断是否给出的图合法,能够满足条件。

在二分图染色的过程中,记录一下两种颜色的个数a,b,那么最终的答案就是对于每个图的2^a+2^b再求和。

注意一下单独一个点可能有1,2,3三种情况。

代码如下:

#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
const int N = 3e5+;
int T;
int n,m,flag,num,sum;
vector <int> g[N];
int color[N];
void dfs(int u,int c){
color[u]=c;sum++;
if(color[u]==) num++;
if(flag) return ;
for(auto v:g[u]){
if(!color[v]) dfs(v,-c);
else if(color[v]==c){
flag=;
return ;
}
}
return ;
}
ll quick(ll a,int b){
ll ans = ;
while(b){
if(b&) ans=(ans*a)%MOD;
a=(a*a)%MOD;
b>>=;
}
return ans ;
}
int main(){
cin>>T;
while(T--){
scanf("%d%d",&n,&m);flag=;
for(int i=;i<=n;i++) g[i].clear(),color[i]=;
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);g[v].push_back(u);
}
int tot =;
ll ans =;
for(int i=;i<=n;i++){
if(!color[i] && !flag){
num=;sum=;
dfs(i,);
if(sum==) ans=(ans*)%MOD;
else ans=(ans*(quick(,num)+quick(,sum-num))%MOD)%MOD;
}
}
if(flag) printf("0\n");
else printf("%I64d\n",ans);
}
return ;
}

Educational Codeforces Round 56 (Rated for Div. 2) ABCD的更多相关文章

  1. Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))

    题目链接: https://codeforces.com/contest/1093/problem/G 题目: 题意: 在k维空间中有n个点,每次给你两种操作,一种是将某一个点的坐标改为另一个坐标,一 ...

  2. Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph 【规律 && DFS】

    传送门:http://codeforces.com/contest/1093/problem/D D. Beautiful Graph time limit per test 2 seconds me ...

  3. Educational Codeforces Round 56 (Rated for Div. 2) D

    给你一个无向图 以及点的个数和边  每个节点只能用1 2 3 三个数字 求相邻 两个节点和为奇数   能否构成以及有多少种构成方法 #include<bits/stdc++.h> usin ...

  4. Educational Codeforces Round 56 (Rated for Div. 2)

    涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...

  5. Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题

    F - Vasya and Array dp[ i ][ j ] 表示用了前 i 个数字并且最后一个数字是 j 的方案数. dp[ i ][ j ] = sumdp [i - 1 ][ j ], 这样 ...

  6. Educational Codeforces Round 56 (Rated for Div. 2) E(1093E) Intersection of Permutations (树套树,pb_ds)

    题意和分析在之前的链接中有:https://www.cnblogs.com/pkgunboat/p/10160741.html 之前补题用三维偏序的cdq的分治A了这道题,但是感觉就算比赛再次遇到类似 ...

  7. Educational Codeforces Round 56 (Rated for Div. 2) F. Vasya and Array

    题意:长度为n的数组,数组中的每个元素的取值在1-k的范围内或者是-1,-1代表这个元素要自己选择一个1-k的数字去填写,然后要求填完的数组中不能出现连续长度大于len的情况,询问填空的方案数. 题解 ...

  8. Educational Codeforces Round 56 (Rated for Div. 2) D. Beautiful Graph (二分图染色)

    题意:有\(n\)个点,\(m\)条边的无向图,可以给每个点赋点权\({1,2,3}\),使得每个点连的奇偶不同,问有多少种方案,答案对\(998244353\)取模. 题解:要使得每个点所连的奇偶不 ...

  9. Educational Codeforces Round 54 (Rated for Div. 2) ABCD

    A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...

随机推荐

  1. ruby 数据类型String

    一.字符串创建 单引号包含,不支持转义符和内嵌表达式#{}(插值符) str = 'hello world!' 双引号包含 str = "hello world!" 使用%,%Q, ...

  2. Windows Store App下代码加载page resource和resw文件里的string

    加载page resource 在page的code behind里: this.Resources["textBoxStyle"] 加载resw文件里的string: Resou ...

  3. poj3308 Paratroopers

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

  4. WPF中,如何将Vista Aero效果扩展到整个窗口

    原文:WPF中,如何将Vista Aero效果扩展到整个窗口   WPF中,如何将Vista Aero效果扩展到整个窗口                                         ...

  5. 7 tftp

    1. TFTP协议介绍 TFTP(Trivial File Transfer Protocol,简单文件传输协议) 是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输的协议 特点: ...

  6. ajax设置自定义头

    一.setting参数 headers $.ajax({ headers: {        Accept: "application/json; charset=utf-8"  ...

  7. ethtool speed HowTo : Change Speed and Duplex of Ethernet card in Linux

    To change Speed and Duplex of an ethernet card, we can use ethtool - a Linux utility for Displaying ...

  8. C#读写txt文件的两种方法介绍 v

    C#读写txt文件的两种方法介绍 1.添加命名空间 System.IO; System.Text; 2.文件的读取 (1).使用FileStream类进行文件的读取,并将它转换成char数组,然后输出 ...

  9. 关于C#数据类型自己的理解

    电脑CUP处理程序的运行.cpu里分为一级缓存,二级缓存,还有三级缓存,之后是内存里的东西. 栈存放在一级缓存里,所以cup调用速度最快,处理起来也效率也最高,但是大小很小,能存放的东西很少. 堆存放 ...

  10. OpenCV入门:(六:基础画图函数)

    有时程序中需要画一些基础的图形,例如直线,矩形,椭圆以及多边形.OpenCV中当然有此类函数. 1.函数介绍 直线line: , , ) img – 图像 pt1 – 直线起点 pt2 – 直线终点 ...