Codeforces Round #467(Div2)题解
凌晨起来打CF,0:05,也是我第一次codeforces
第一题:
我刚开始怀疑自己读错题了,怎么会辣么水。
判除了0的数字种类
#include <cstdio>
;
];
int main(){
scanf("%d",&n);int i;
;i<=n;++i){
;
}
printf("%d",ans);
}
第二题:让你找一个x使x<=y且x不能被[2,p]内的数整除,使x尽量大
其实是暴力枚举。
#include <cstdio>
int p,y;
bool ck(int x){
int i;
;i*i<=x&&i<=p;++i));
;
}
int main(){
scanf("%d%d",&p,&y);
int i;
for(i=y;i>p;--i)if(ck(i)){
printf("%d",i);
;
}
printf("-1");
}
第三题,模拟题,太水了,不细说:
#include <cstdio>
#include <iostream>
using namespace std;
long long k,d,t;
;
int main(){
scanf(){
printf("%I64d",t);
;
}
)*d;tmp-=k;
;
long long tm=(long long)((double)t/(x+y));ans=tm*(k+tmp);double rt=(double)t-(double)tm*(x+y);
if(rt<=k){
ans+=rt;printf("%lf",ans);
}else{
ans+=k;rt-=k;ans+=rt*(;printf("%lf",ans);
}
}
第四题:
给你一个有向图,问你能否奇数步走到一个初度为0的点,输出路径
初看吓得我以为是SG函数,然而并不是, tarjan+bfs就行了
bfs和dp一起来,这里的dp可以用spfa的方式,用一个可以让元素多次进出的队列,然后搞dp
tarjan用来判能不能平局,如果s以后的路上没有scc,就输出lose
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define maxn 100010
#define maxm 200010
struct edge{int nxt,to;}e[maxm];
];
],inq[maxn];
void add(int u,int v){e[++pos]=(edge){head[u],v},head[u]=pos;}
stack<int>s;
queue<int>q;
void tar(int u){
dnf[u]=low[u]=++dfs_cnt;s.push(u);int i;
for(i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(!dnf[v]){
tar(v);low[u]=min(low[u],low[v]);
}else if(!scc[v])low[u]=min(low[u],dnf[v]);
}
if(low[u]==dnf[u]){
for(scc_cnt++;;){
int x=s.top();s.pop();++scc_size[scc_cnt];
scc[x]=scc_cnt;if(x==u)break;
}
}
}
void dfs(int u,int sta){
if(u){
dfs(pre[u][sta],sta== ? :);
ans[++ans[]]=u;
}
}
int main(){
scanf("%d%d",&n,&m);int i;
;i<=n;++i){
int k,x;scanf("%d",&k);
while(k--){
scanf("%d",&x);add(i,x);++out[i];
}
}
scanf("%d",&st);
;i<=n;++i)if(!dnf[i])tar(i);
;
dp[st][]=;q.push(st);inq[st]=;
while(!q.empty()){
;
)flg=;
for(i=head[u];i;i=e[i].nxt){
int v=e[i].to;
] && dp[v][]==){
dp[v][]=;pre[v][]=u;;
}
] && dp[v][]==){
dp[v][]=;pre[v][]=u;;
}
}
}
;i<=n;++i)] && ){
dfs(i,);printf("Win\n");
;j<=ans[];++j)printf(;
}
if(flg)printf("Draw");else printf("Lose");
}
T5:构造题
题意是给定一个字符串S1,S2(这不是两个吗。。。)长度2e3以下
定义操作:
将s1的后缀x个进行一次反转,再放到字符串首
如果操作多余6100,则答案无效
分析:
对于一个字符串:ABxC(A:与s2后缀相符的字符串,x:S2后缀A之前的那个字符,也就是我们要将x放到A前面,B,C:都是无关紧要的乱序字符串)
ABxC->CxBA(每个都反转)->ABCx->xABC 操作次数3n
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 2010
char s1[maxn],s2[maxn];
],h1[],h2[];
int idx(char c){return c-'a';}
bool jg(){
;i<n;++i);
;
}
bool ck(int l1,int r1,int l2,int r2){
;
;
}
int main(){//freopen("o1.txt","w",stdout);
scanf("%d",&n);
scanf(;
int i;
;i<n;++i)h1[idx(s1[i])]++,++h2[idx(s2[i])];
;i<;++i)if(h1[i]!=h2[i]){
printf(;
}
while(!jg()){
,bpos=-,cpos=-,xpos=-;
,i-,n-i,n-);--i);len=i;
apos=len-;
;s1[i]!=s2[n-len-];++i);
bpos=i-;xpos=i;cpos=n;
ans[++ans[]]=n;ans[++ans[]]=bpos+;ans[++ans[]]=;
char tmp[maxn];
tmp[]=s2[n-len-];;
;i<=apos;++i)tmp[++ps]=s1[i];
;i<=bpos;++i)tmp[++ps]=s1[i];
//for(i=xpos+1;i<n;++i)tmp[++ps]=s1[i];
;i>=xpos+;--i)tmp[++ps]=s1[i];
;i<n;++i)s1[i]=tmp[i];
}
printf(]);
;i<=ans[];++i)printf("%d ",ans[i]);
}
Codeforces Round #467(Div2)题解的更多相关文章
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- CodeForces round 967 div2 题解(A~E)
本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉 最后一题没搞懂怎么做,恳请大神指教 欢迎大家在评论区提问. A Mind the Gap 稳定版题面 https://cn.vjudge.net/ ...
- Codeforces Round #407 div2 题解【ABCDE】
Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...
- Codeforces Round#704 Div2 题解(A,B,C,D,E)
FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...
- Codeforces Round#687 Div2 题解
打这场的时候迷迷糊糊的,然后掉分了( A Prison Break: 题面很复杂,但是题意很简单,仅需求出从这个点到四个角的最大的曼哈顿距离即可 #include <bits/stdc++.h& ...
- CodeForces Round #516 Div2 题解
A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...
- Codeforces Round #467 (div.2)
Codeforces Round #467 (div.2) 我才不会打这种比赛呢 (其实本来打算打的) 谁叫它推迟到了\(00:05\) 我爱睡觉 题解 A. Olympiad 翻译 给你若干人的成绩 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
随机推荐
- URAL1517Freedom of Choice(后缀数组)
Background Before Albanian people could bear with the freedom of speech (this story is fully describ ...
- BZOJ5314: [Jsoi2018]潜入行动
BZOJ5314: [Jsoi2018]潜入行动 https://lydsy.com/JudgeOnline/problem.php?id=5314 分析: 裸树形背包,设\(f[x][i][0/1] ...
- 【LeetCode】084. Largest Rectangle in Histogram
题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...
- 洛谷【P1898】缘分计算
我对模拟的理解:http://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.luogu.org/problemnew/show/P189 ...
- bzoj 1711 Dining吃饭 —— 最大流
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1711 食物一列,牛拆点,饮料一列. 代码如下: #include<cstdio> ...
- 1 slow requests are blocked > 32 sec解决方法
[root@node1 ~]# ceph -s cluster: id: b8b4aa68-d825-43e9-a60a-781c92fec20e health: HEALTH_WARN Reduce ...
- k8s 基础(4) k8s安装
转自 http://www.cnblogs.com/informatics/p/7389806.html 安装和配置 从github.com/kubernetes/kubernetes上下载1.6.8 ...
- Docker Compose实例
采用java -jar启动 nohup java -jar web--SNAPSHOT.jar --spring.profiles.active=test --server.port= & 采 ...
- JAVA基础知识总结2(语法基础)
关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:暂时还未规定为关键字的单词,保留准备日后要使用的单词. 标识符:开发人员程序中自定义名词,比如类名,变量名,函数名. PS:1.不能使用关键字. ...
- java poi导出Excel 总结
首先下载 Apache 的POI jar包 将更目录下的poi-3.8-20120326.jar 和lib下的三个jar包导入 如下图: 首先必须搞一个通用的工具类,网上找的,能用就行,java就是这 ...