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 ...
随机推荐
- Linux环境搭建SVN服务
一.准备工作 首先要保证自己的linux电脑能上外网,我这电脑因为是新的,没有配置网络,所以再这块花费了点时间. 1.检查ip信息 >ifconfig 2.检查DNS服务器 >cat / ...
- linux 负载各项查看命令
free -h top -c 查看使用情况 sar -r/s/b 查看IO状态 iostat -x 1 10 查看服务器的状态 vmstat 查看内存使用率最后的前10个进程 ps -aux |sor ...
- Mybatis 处理日期格式自动转换
java.lang.String和java.util.Date之间自动转换 @DateTimeFormat(pattern="yyyy-MM-dd")//页面写入数据库时格式化 @ ...
- BNUOJ 5629 胜利大逃亡(续)
胜利大逃亡(续) Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 1 ...
- SPOJ 3267 D-query (可持久化线段树,区间重复元素个数)
D-query Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair ...
- 【Codevs1237&网络流24题餐巾计划】(费用流)
题意:一个餐厅在相继的 N 天里,每天需用的餐巾数不尽相同. 假设第 i 天需要 ri块餐巾(i=1,2,…,N).餐厅可以购买新的餐巾,每块餐巾的费用为 p 分: 或者把旧餐巾送到快洗部,洗一块需 ...
- springMVC @Value的使用
@Value 功能:将一个SpEL(SpEL:spring表达式类似于ognl)表达式结果映射到功能处理方法的参数上 例子:获取系统参数'java.vm.version'的值给到变量jvmVersio ...
- POJ 1064_Cable master
题意: 给定一系列长度的电缆,将他们切成K条相等长度的电缆,问每条最长有多长? 分析: 对长度进行二分,判断能否满足K条. 二分搜索: 在求解最大化或最小化问题中,能够比较简单的判断条件是否满足,那么 ...
- POJ 3268_Silver Cow Party
题意: n个地方,标号1~n,每个地方都有一头牛,现在要他们都去往标号为x的地方,再从x返回,每条道路都是单向的,求所有牛走的来回的最短路中的最大值. 分析: 注意在求每头牛走到x时,挨个算肯定超时, ...
- codevs——1742 爬楼梯
1742 爬楼梯 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 小明家外面有一个长长的楼梯,共N阶.小明的 ...