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\)个元素,剩下 ...
随机推荐
- BZOJ4974 大视野1708月赛 字符串大师
传送门 题目大意 给定一个字符串的每一个前缀的最短循环节长度,求符合要求的字典序最小的字符串. 题解 给定循环节最短长度就是给定了这个字符串$kmp$的$next$数组,即$X_i=i-next_i$ ...
- CodeForces - 1017 C. The Phone Number(数学)
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number! The ...
- HDU1370Biorhythms(中国剩余定理||暴力)
Some people believe that there are three cycles in a person's life that start the day he or she is b ...
- 非系统表空间损坏,rman备份恢复
实验条件:有完整可用备份--查询表空间情况SQL> select tablespace_name,status from dba_tablespaces;TABLESPACE_NAME STAT ...
- 冷备手工完全恢复(recover database,recover tablespace,recover datafile)
冷备手工完全恢复 1. 手工完全恢复三种级别: recover database: 所有或大部分datafile丢失,一般是在mount状态完成.recover tablespace: 非关 ...
- 快速排序的JavaScript实现
思想 分治的思想,将原始数组分为较小的数组(但没有像归并排序一样将它们分隔开). 主元选择: 从数组中任意选择一项作为主元,通常为数组的第一项,即arr[i]:或数组的中间项, arr[Math.fl ...
- centos下升级mysql5.5.47到5.7.14操作过程
一. 查看已安装Mysql基础信息通过mysql –V 查看下mysql版本可以通过命令find / -name mysql 得到下面信息 1.安装目录[root@jjxnhd-192-10 mysq ...
- loadrunner手动生成脚本函数
1.点击insert
- java基础知识(2)---语法基础
二:java语法基础: 1,关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:其实就是还没有赋予特殊含义,但是准备日后要使用过的单词. 2,标示符:其实就是在程序中自定义的名词.比如类名,变量名 ...
- TS学习之类
定义类 class Person { name: string; //属性 constructor(_name: string) { this.name = _name; } //构造函数 sayHe ...