Codeforces Round #369 (Div. 2) 套题
A:模拟水题不说
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset> using namespace std;
typedef long long LL;
const int N= 1e3+;
char s[N][];
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%s",s[i]+);
bool flag=false;
for(int i=;i<=n;++i){
if(s[i][]==s[i][]&&s[i][]=='O'){
flag=true;
s[i][]=s[i][]='+';
break;
}
if(s[i][]==s[i][]&&s[i][]=='O'){
flag=true;
s[i][]=s[i][]='+';
break;
}
}
if(flag)printf("YES\n");
else printf("NO\n");
if(flag)
for(int i=;i<=n;++i)printf("%s\n",s[i]+);
return ;
}
B:n*n的方阵,只有一个位置是未填数的,然后问填数以后,行和列和主副对角线和相等
O(n^2)模拟即可(这题FST了,由于输出格式不太对,对了这个也许能上更多分吧)
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset> using namespace std;
typedef long long LL;
const int N= 5e2+;
LL a[N][N];
int main(){
int n,x,y;
scanf("%d",&n);
for(int i=;i<=n;++i){
for(int j=;j<=n;++j){
scanf("%I64d",&a[i][j]);
if(a[i][j]==){
x=i;
y=j;
}
}
}
if(n==){
printf("1\n");
return ;
}
LL sum=;
if(x==)
for(int i=;i<=n;++i)sum+=a[][i];
else
for(int i=;i<=n;++i)sum+=a[][i];
LL ret=-;
for(int i=;i<=n;++i){
LL tmp=;
for(int j=;j<=n;++j)
tmp+=a[i][j];
if(i==x){
if(tmp<sum){
if(ret!=-&&ret!=sum-tmp){
printf("-1\n");
return ;
}
else ret=sum-tmp;
}
else {
printf("-1\n");
return ;
}
}
else{
if(sum!=tmp){
printf("-1\n");
return ;
}
}
}
for(int j=;j<=n;++j){
LL tmp=;
for(int i=;i<=n;++i)
tmp+=a[i][j];
if(j==y){
if(tmp<sum){
if(ret!=-&&ret!=sum-tmp){
printf("-1\n");
return ;
}
else ret=sum-tmp;
}
else {
printf("-1\n");
return ;
}
}
else{
if(sum!=tmp){
printf("-1\n");
return ;
}
}
}
LL tmp=;
for(int i=;i<=n;++i)tmp+=a[i][i];
if(x==y){
if(tmp<sum){
if(ret!=-&&ret!=sum-tmp){
printf("-1\n");
return ;
}
else ret=sum-tmp;
}
else {
printf("-1\n");
return ;
}
}
else{
if(sum!=tmp){
printf("-1\n");
return ;
}
}
tmp=;
for(int i=;i<=n;++i)tmp+=a[i][n+-i];
if(x+y==n+){
if(tmp<sum){
if(ret!=-&&ret!=sum-tmp){
printf("-1\n");
return ;
}
else ret=sum-tmp;
}
else {
printf("-1\n");
return ;
}
}
else{
if(sum!=tmp){
printf("-1\n");
return ;
}
}
printf("%I64d\n",ret);
return ;
}
C:赛场上写了个裸的O(n^4)的dp,dp[i][j][k]代表当前是第i个数,这个数是j,分成k块的最小值
由于是时限是2s,而且是CF评测机,不虚
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset> using namespace std;
typedef long long LL;
const int N= 1e2+;
LL dp[N][N][N];
LL p[N][N];
int a[N];
int main(){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;++i)scanf("%d",&a[i]);
for(int i=;i<=n;++i){
for(int j=;j<=m;++j)
scanf("%I64d",&p[i][j]);
}
memset(dp,-,sizeof(dp));
if(a[]!=)dp[][a[]][]=;
else{
for(int i=;i<=m;++i)
dp[][i][]=p[][i];
}
for(int i=;i<=n;++i){
int lim=min(k,i);
if(a[i]!=){
for(int j=;j<=lim;++j){
for(int c=;c<=m;++c){
if(dp[i-][c][j-]!=-&&a[i]!=c){
if(dp[i][a[i]][j]==-)dp[i][a[i]][j]=dp[i-][c][j-];
else dp[i][a[i]][j]=min(dp[i][a[i]][j],dp[i-][c][j-]);
}
if(dp[i-][c][j]!=-&&a[i]==c)
if(dp[i][a[i]][j]==-)dp[i][a[i]][j]=dp[i-][c][j];
else dp[i][a[i]][j]=min(dp[i][a[i]][j],dp[i-][c][j]);
}
}
continue;
}
for(int x=;x<=m;++x){
for(int j=;j<=lim;++j){
for(int c=;c<=m;++c){
if(dp[i-][c][j-]!=-&&x!=c){
if(dp[i][x][j]==-)dp[i][x][j]=dp[i-][c][j-]+p[i][x];
else dp[i][x][j]=min(dp[i][x][j],dp[i-][c][j-]+p[i][x]);
}
if(dp[i-][c][j]!=-&&x==c)
if(dp[i][x][j]==-)dp[i][x][j]=dp[i-][c][j]+p[i][x];
else dp[i][x][j]=min(dp[i][x][j],dp[i-][c][j]+p[i][x]);
}
}
}
}
LL ret=-;
for(int i=;i<=m;++i)
if(dp[n][i][k]!=-){
if(ret==-)ret=dp[n][i][k];
else ret=min(ret,dp[n][i][k]);
}
printf("%I64d\n",ret);
return ;
}
D:这种题很常见,有向环套树,看每个环的反转方案,是2^k-2(k是边数,必须翻一个,不能全翻)
剩下的树上的边翻不翻都可以是2^tot,tot代表树边,然后都乘起来即可
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset>
using namespace std;
typedef long long LL;
const int N = 2e5+;
const LL mod = 1e9+;
int to[N],n;
int vis[N];
LL qpow(LL x,LL y){
LL ret=;
while(y){
if(y&)ret=ret*x%mod;
y>>=;
x=x*x%mod;
}
return ret;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%d",&to[i]);
LL z=n,ret=;
for(int i=;i<=n;++i){
if(vis[i])continue;
int x=i;
while(!vis[x]){
vis[x]=i;
x=to[x];
}
if(vis[x]!=i)continue;
int t=x,cnt=;
do{
++cnt;
t=to[t];
}while(t!=x);
z-=cnt;
ret=1ll*ret*((qpow(,cnt)-+mod)%mod)%mod;
}
ret=ret*qpow(,z)%mod;
printf("%I64d\n",ret);
return ;
}
E:考虑正难则反,概率等于1-A(k,2^n)/2^(nk),然后发现最大公约数只能是2^i,约分即可
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bitset>
using namespace std;
typedef long long LL;
const int N = 2e5+;
const LL mod = 1e6+;
LL qpow(LL x,LL y){
LL ret=;
while(y){
if(y&)ret=ret*x%mod;
x=x*x%mod;y>>=;
}
return ret;
}
int main(){
LL n,k;
scanf("%I64d%I64d",&n,&k);
if(n<=&&k>1ll<<n){
printf("1 1\n");
return ;
}
LL num=;
for(LL i=k-;i;i>>=){
num+=i/;
}
LL b=,a=qpow(,n);
for(LL i=;i<=k-;++i){
LL tmp=(a-i+mod)%mod;
b=b*tmp%mod;
if(tmp==)break;
}
LL inv=qpow(qpow(,num),mod-);
a=qpow(a,k-);
a=a*inv%mod;
b=b*inv%mod;
b=(a-b+mod)%mod;
printf("%I64d %I64d\n",b,a);
return ;
}
Codeforces Round #369 (Div. 2) 套题的更多相关文章
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- Codeforces Round #361 (Div. 2) 套题
A - Mike and Cellphone 问有没有多解,每个点按照给出的序列用向量法跑一遍 #include<cstdio> #include<cstring> #incl ...
- Codeforces Round #367 (Div. 2) 套题
吐槽:只能说是上分好场,可惜没打,唉 A:Beru-taxi (水题,取最小值) #include <cstdio> #include <cstring> #include & ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...
随机推荐
- STM32F407 跑马灯 库函数版 个人笔记
原理图: MCU在开发板原理图的第二页,LED在开发板原理图的第三页 由图可知,PF9 ,PF10 若输出低电平则灯亮,高电平则灯灭 选推挽输出 代码步骤 使能IO口时钟. 调用函数RCC_AHB1P ...
- javaWeb学习之 Filter过滤器----https://www.cnblogs.com/xdp-gacl/p/3948353.html
https://www.cnblogs.com/xdp-gacl/p/3948353.html
- centos7安装mysql5.7.19及配置远程连接
centos7安装mysql5.7.19及配置远程连接------https://blog.csdn.net/Lh19931122/article/details/77996213
- 慕课笔记利用css进行布局【一列布局】
<html> <head> <title>一列布局</title> <style type="text/css"> bo ...
- poj 1182用向量的思考模式
不会写果断看答案http://cavenkaka.iteye.com/blog/1489588 #include<stdio.h> #include<string.h> #de ...
- NOIP2015提高组D1T3 斗地主
问一副排n张,n<=23最少打几次打完,数据组数T<=100. 面向数据编程.. 前30分:乱暴力?没有顺子,把单.对子.炸弹.三张.王炸.三带一判一次即可. 前70分:状压,先预处理哪些 ...
- MeepoPS基本使用方法
MeepoPS基本使用 MeepoPS是Meepo PHP Socket的缩写. 旨在提供高效稳定的由纯PHP开发的多进程SocketService. MeepoPS可以轻松构建在线实时聊天, 即时游 ...
- Google Protocol Buffer 的使用(一)
一.什么是Google Protocol Buffer下面是官网给的解释:Protocol buffers are a language-neutral, platform-neutral exten ...
- SQL Server中迁移数据的几种方法
1.通过工具"DTS"的设计器进行导入或者导出 DTS的设计器功能强大,支持多任务,也是可视化界面,容易操作,但知道的人一般不 多,如果只是进行SQL Server数据库中部分表的 ...
- anaconda是个啥?
Anaconda具有跨平台(win/mac/linux).包管理(类似于pip).环境管理(类似于virtualenv)的特点,因此很适合快速在新的机器上部署Python环境 Anaconda利用工具 ...