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 ...
随机推荐
- 零基础入门学习Python(18)--函数:灵活即强大
前言 上一节课我们基本介绍Python函数的用法,这一节课我们主要针对函数的参数进行进一步的深入学习. 知识点 形参(parameter)和实参(argument) >>> def ...
- 利用WITH AS改写SQL
报表程序中一段SQL语句. 优化前: 返回:3952 耗时:224s SQL 代码: select to_date(nvl(pro.value, '1900-01-01 00:00:00'), 'YY ...
- python logging 日志使用
https://docs.python.org/3/library/logging.html1.日志级别 日志一共分成5个等级,从低到高分别是:DEBUG INFO WARNING ERROR CRI ...
- Linux 网卡配置
网卡配置(环境CentOS 6.7) 图形界面修改: # 在命令行直接输入setup进入配置 1.[root@mingyaun ~]# setup 2.NetWork configuration 3. ...
- stm8l定时器中的ARPE
• Auto-reload preload enabled (ARPE bit set in the TIM1_CR1 register). In this mode,when data is wri ...
- 集训第四周(高效算法设计)I题 (贪心)
Description Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshe ...
- dynamic-imports & web components & html dynamic import
dynamic-imports web components & html dynamic import https://github.com/webcomponents/html-impor ...
- Writing Code-Codeforces511C**
http://codeforces.com/problemset/problem/544/C 完全背包 dp[i][j]表示第i行有j个bug #include<stdio.h> #inc ...
- Eclipse使用Maven时,修改默认中央仓库后的配置报错找不到包的问题解决
一般在公司内容配置Maven时会在settings.xml文件下配置私服nexus地址,那么修改完之后在Eclipse中如果不指定用户目录级别的settings.xml文件会出现找不到包的问题. se ...
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...