A. Sasha and Sticks

题目链接:http://codeforces.com/contest/832/problem/A

题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sasha先取,问Sasha是否可以取胜。

代码:

 //Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=;
using namespace std;
typedef long long LL;
int main() {
ios::sync_with_stdio(false);cin.tie();
LL n,k;
LL ct;
cin>>n>>k;
if(n%k==){
ct=n/k;
}
else ct=n/k;
if(ct%){cout<<"YES"<<endl;}
else cout<<"NO"<<endl;
return ;
}

B. Petya and Exam

题目链接:http://codeforces.com/contest/832/problem/B

题目意思:一个xjb大模拟。第一行是好字符(26个),除此之外都是坏字符,第二行是B字符串,B中问号可以change为好字符,* 只能change为坏字符串(字符可以有可以0~MAX个),接下来n次询问,每次给出目标C字符串,问B可以change为C么?

思路:这个题真的wa了很多发啊…………,分四种情况:1.询问串长度大于模式串且差大于1;2.询问串长度大于模式串且差等于1,3.询问串长度等于模式串;4.询问串长度小于模式串。

其中在情况1的时候,还要判断是否出现过*,因为可能没有出现过*,整体的思路就是先把*代表东西补出来,然后安慰比较久可以了。

代码:

 //Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
const long long N=1e5+;
using namespace std;
char a[N],b[N];
int la,lb,lc,lm;
int check[]={};
typedef long long LL;
int main() {
ios::sync_with_stdio(false);cin.tie();
cin>>a>>b;
la=strlen(a);lb=strlen(b);
for(int i=;i<la;i++) check[a[i]-'a']=;
int n;
cin>>n;
while(n--){
char c[N];cin>>c;
int lc=strlen(c);
lm=lb-lc;
int flag=;
if(lm>) {cout<<"NO"<<endl;continue;}
else if(lm==){
int h=;
for(int i=;i<lb;i++) if(b[i]=='*') {h=;break;}
if(h){
for(int i=,j=;j<lc;i++){
if(b[i]=='*') {continue;}
else if(b[i]=='?'){
if(check[c[j]-'a']==) {flag=;break;}
}
else if(b[i]!=c[j]){
flag=; break;
}
j++;
}
}
else flag=; }
else if(lm==){
for(int i=;i<lb;i++){
if(b[i]=='*'||b[i]=='?'){
if(b[i]=='*'){
if(check[c[i]-'a']){flag=;break;}
}
else{
if(check[c[i]-'a']==){flag=;break;}
}
}
else if(b[i]!=c[i]){flag=;break;}
}
}
else if(lm<){
char mb[N];
lm=-lm+;
//cout<<lm<<endl;
int ct=;
for(int i=,j=;i<lb;i++){
if(b[i]=='*'){
for(int k=;k<lm;k++){
if(check[c[j]-'a']){ mb[ct++]='?';}
else mb[ct++]=c[j++];
}
continue;
}
else if(b[i]=='?'){
if(check[c[j]-'a']) mb[ct++]=c[j];
else mb[ct++]='?';
}
else if(b[i]!=c[j]) { mb[ct++]=b[i];}
else mb[ct++]=c[j];
j++;
}
if(ct<lc) flag=;
else{
for(int i=;i<lc;i++){
if(mb[i]!=c[i]){
flag=;break;
}
}
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl; }
return ;
}

D. Misha, Grisha and Underground

题目链接:http://codeforces.com/contest/832/problem/D

题目意思:LCA模板题,可以数到标签的数量等于(dist(a,b)+dist(c,b)-dist(a,c))/2+1。两点之间的距离可以用LCA算出。这里LCA用的是基于DFS序的RMQ算法。

代码:

 //Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long N=+;
using namespace std;
typedef long long LL;
typedef int II;
vector<int>p[N];
II n,q;
II fr[*N],de[*N],pos[*N],tot=;
II d[N][];
void RMQ_init(){
for(II i=;i<=tot;i++) d[i][]=fr[i];
for(II j=;(<<j)<=tot;j++)
for(II i=;i+(<<j)-<=tot;i++){
II x=d[i][j-];
II y=d[i+(<<(j-))][j-];
if(de[x]<de[y]) d[i][j]=x;
else d[i][j]=y;
}
}
II RMQ(II x,II y){
II L=min(pos[x],pos[y]),R=max(pos[x],pos[y]);
II k=log((double)(R-L+))/log(2.0);
II t1=d[L][k];
II t2=d[R-(<<k)+][k];
if(de[t1]<de[t2]) return t1;
else return t2;
} void dfs(II u,II pre,II dep){
fr[++tot]=u;pos[u]=tot;de[u]=dep;
for(II i=;i<p[u].size();i++){
II v=p[u][i];
if(v==pre) continue;
dfs(v,u,dep+);
fr[++tot]=u;
}
} II dist(II x,II y){
II qe=RMQ(x,y);
int len=de[x]+de[y]-*de[qe];
return len;
}
int main(){
ios::sync_with_stdio(false);cin.tie();
cin>>n>>q;
for(II i=;i<=n;i++){
II x;
cin>>x;
p[i].push_back(x);p[x].push_back(i);
}
dfs(,-,);
RMQ_init();
while(q--){
II x,y,z;
cin>>x>>y>>z;
II t,ans=minn;
II lxy=dist(x,y),lxz=dist(x,z),lyz=dist(y,z);
t=(lxy+lyz-lxz)/+;//y为终点
ans=max(t,ans);
t=(lxy+lxz-lyz)/+;//x为终点
ans=max(t,ans);
t=(lxz+lyz-lxy)/+;//z为终点
ans=max(t,ans);
cout<<ans<<endl;
}
return ;
}

Codeforces Round #425 (Div. 2))——A题&&B题&&D题的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  3. Codeforces Round #384 (Div. 2) C. Vladik and fractions 构造题

    C. Vladik and fractions 题目链接 http://codeforces.com/contest/743/problem/C 题面 Vladik and Chloe decided ...

  4. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  5. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

  6. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  7. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  8. Codeforces Round #114 (Div. 1) A. Wizards and Trolleybuses 物理题

    A. Wizards and Trolleybuses Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  9. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

随机推荐

  1. 每日英语:Stalled Project Shows Why China's Economy Is Wobbling

    CAOFEIDIAN, China  $91 billion industrial project here, mired in debt and unfulfilled promise, sugge ...

  2. HUD 2544 最短路 迪杰斯特拉算法

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. lodop简单入门教程

    lodop简单入门 1 安装(这个不介绍,下载安装即可) 声明只能装windows,linux不能装,所以linux 服务器要使用直接使用http://localhost:8000/CLodopfun ...

  4. phoenix系统创建语句

    CREATE TABLE SYSTEM."CATALOG"( TENANT_ID VARCHAR NULL, TABLE_SCHEM VARCHAR NULL, TABLE_NAM ...

  5. 今天遇到个PHP不知原因的报内部错误

    今天遇到个PHP不知原因的报内部错误 纠结了很久想尽了办法,1.apache日志 2.错误级别 ,还差点就把自己写的那个破烂不堪的日志系统加上去了 纠结了很久还是无果,在最终,最终发现了 原来是类命名 ...

  6. Android——excise(用线性布局、表格布局、相对布局做发送邮件界面)

    LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...

  7. QQ会员活动运营平台架构设计实践——高效自动化运营

    QQ会员活动运营平台(AMS),是QQ会员增值运营业务的重要载体之一,承担海量活动运营的Web系统.在过去四年的时间里,AMS日请求量从200-500万的阶段,一直增长到日请求3-5亿,最高CGI日请 ...

  8. select 5种子句介绍

    一.Where 条件查询 ①where expression 用法:expression为真,则该行取出 运用场合 各种条件查询场合,如按学号查学生,按价格查商品,按发布时间查新闻等 ②select ...

  9. 【2015/7/22】SqlServer卸载重装全攻略!

    请大家大声地告诉我,哪个软件最恶心. 装了之后跟在电脑里面糊了一层泥,甩都甩不干净.之前手贱,重装系统后装了sqlserver2014的试用版.可惜过了半年试用期就到了.然后重装2012.2014卸载 ...

  10. arduino波特率

    波特率,也就是数据通信的速度,它是目前比较流行的传输速率.以这个速度通信的话,每发送一个字节(Byte)到控制端需要的时间大概是1毫秒.需要注意的是,为了精确控制四轴的平衡,我们需要尽量在短时间内多读 ...