Codeforces Round #425 (Div. 2)比赛总结
来源:互联网 发布:儒道数据分析地址 编辑:程序博客网 时间:2024/06/16 01:58
心累。。上次写的总结不知道怎么搞的被吞了。。只能再写一遍了。。
这次就写BCD吧。。
B题是阅读题,写程序什么的不难。注意细节。。
#include<iostream>#include<set>#include<string>#include<cstring>using namespace std;int main(){ char s[30]; cin >> s; set<char>S; set<int>Index; for (int i = 0;i < strlen(s);i++) S.insert(s[i]); string a; cin >> a; int bad=-1; for (int i = 0;i < a.size();i++) { if (a[i] == '?')Index.insert(i); else if (a[i] == '*')bad = i; } int t; cin >> t; string temp; for (int i = 0;i < t;i++) { cin >> temp; bool flag = true; if (temp.size() == a.size()) { for (int j = 0;j < temp.size();j++) { if (Index.count(j) && !S.count(temp[j])) { flag = false;break; } else if (j != bad && !Index.count(j) && temp[j] != a[j]) { flag = false;break; } else if (j == bad&&S.count(temp[j])) { flag = false;break; } } } else if (temp.size() > a.size()) { if (bad == -1) { flag = false; } else { int thebad = bad; for (int j = 0;j < thebad;j++) { if (Index.count(j) && !S.count(temp[j])) { flag = false;break; } else if (!Index.count(j) && temp[j] != a[j]) { flag = false;break; } } int Left = temp.size() - a.size(); int j; for ( j = thebad;j <= thebad + Left;j++) { if (S.count(temp[j])) { flag = false;break; } } for (int k = thebad + 1;k < a.size();k++, j++) { if (Index.count(k) && !S.count(temp[j])) { flag = false;break; } else if ( !Index.count(k) && temp[j] != a[j]) { flag = false;break; } } } } else { if (a.size() - temp.size() > 1)flag = false; else { int thebad = bad; int j; for ( j = 0;j < thebad;j++) { if (Index.count(j) && !S.count(temp[j])) { flag = false;break; } else if ( !Index.count(j) && temp[j] != a[j]) { flag = false;break; } } for (int k = thebad + 1;k < a.size();k++, j++) { if (Index.count(k) && !S.count(temp[j])) { flag = false;break; } else if (!Index.count(k) && temp[j] != a[j]) { flag = false;break; } } } } if (flag)cout << "YES" << endl; else cout << "NO" << endl; } return 0;}
C题 二分时间 不难
#include<iostream>#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;typedef long long ll;struct node{ int x,v,dir;} nodes[100005];int n,s;bool check(double limit){ bool Left=false,Right=false; long long Leftl=(ll)1e6,LeftR=0,Rightl=(ll)1e6,RightR=0; for(int i=1; i<=n; i++) { //if(Left&&Right)break; if(nodes[i].dir==1) { double temp=limit*(nodes[i].v+s); if(temp>=nodes[i].x)Left=true; else continue; temp=limit*nodes[i].v; double v=nodes[i].v; if(temp>=nodes[i].x){Leftl=0;LeftR=1e6;continue;} else { double min_time=(double)(nodes[i].x-limit*nodes[i].v)/s;//最少需要有多少时间有光速的加成 ll lo=nodes[i].x+floor((limit-min_time)*(s-nodes[i].v));//这种情况下炸弹最右的位置 Leftl=min(Leftl,(ll)(nodes[i].x)); LeftR=max(LeftR,lo); } } else { double temp=limit*(nodes[i].v+s); if(temp>=(1e6-nodes[i].x))Right=true; else continue; temp=limit*nodes[i].v; double v=nodes[i].v; if(temp>=(1e6-nodes[i].x)){Rightl=0;RightR=1e6;continue;} else { double min_time=(double)(1e6-nodes[i].x-nodes[i].v*limit)/s; ll lo=nodes[i].x-floor((limit-min_time)*(s-nodes[i].v)); Rightl=min(Rightl,lo); RightR=max(RightR,(ll)nodes[i].x); } } } if(!Left||!Right)return false; if(Leftl>LeftR||Rightl>RightR)return false; return !(Leftl>RightR||Rightl>LeftR);}int main(){ scanf("%d%d",&n,&s); for(int i=1; i<=n; i++) { scanf("%d%d%d",&nodes[i].x,&nodes[i].v,&nodes[i].dir); } double l=0; double r=1e6; double mid; double ans; for(int i=1; i<=50; i++) { mid=(l+r)/2.0; if(check(mid)) { r=mid; ans=mid; } else l=mid; } printf("%.7f\n",ans ); return 0;}
D题 lca模版题 有点难。。毕竟第一次做lca
#include<iostream>#include<math.h>#include<stdio.h>#include<cstring>using namespace std;const int N=100005;const int M=25;int _pow[M];int head[N];int ver[2*N];int R[2*N];int first[N];int dir[N];int dp[2*N][M];bool vis[N];int tot;int cnt;struct edge{ int u,v,w,next;}e[2*N];void dfs(int u,int dep){ vis[u]=true;ver[++tot]=u;first[u]=tot;R[tot]=dep; for(int k=head[u];k!=-1;k=e[k].next) if(!vis[e[k].v]) { int v=e[k].v,w=e[k].w; dir[v]=dir[u]+w; dfs(v,dep+1); ver[++tot]=u; R[tot]=dep; }}void ST(int len){ int K=(int)(log((double)len)/log(2.0)); for(int i=1;i<=len;i++)dp[i][0]=i; for(int j=1;j<=K;j++) for(int i=1;i+_pow[j]-1<=len;i++) { int a=dp[i][j-1],b=dp[i+_pow[j-1]][j-1]; if(R[a]<R[b])dp[i][j]=a; else dp[i][j]=b; }}int RMQ(int x,int y){ int K=(int)(log((double)(y-x+1))/log(2.0)); int a=dp[x][K],b=dp[y-_pow[K]+1][K]; if(R[a]<R[b])return a; else return b;}int LCA(int u,int v){ int x=first[u],y=first[v]; if(x>y)swap(x,y); int res=RMQ(x,y); return ver[res];}void addedge(int u,int v){ e[cnt].u=u; e[cnt].v=v; e[cnt].w=1; e[cnt].next=head[u]; head[u]=cnt++;}int getdis(int u,int v){ int fa=LCA(u,v); return dir[u]+dir[v]-2*dir[fa];}void init(){ for(int i=0;i<=M;i++) _pow[i]=(1<<i); memset(head,-1,sizeof(head));}int main(){ init(); int n,q; int p; scanf("%d%d",&n,&q); for(int i=2;i<=n;i++) { scanf("%d",&p); addedge(i,p); addedge(p,i); } dfs(1,1); ST(tot); int a,b,c; for(int i=1;i<=q;i++) { scanf("%d%d%d",&a,&b,&c); int dis1=getdis(a,b); int dis2=getdis(a,c); int dis3=getdis(b,c); int len1=(dis1+dis2-dis3)/2+1; int len2=(dis1+dis3-dis2)/2+1; int len3=(dis2+dis3-dis1)/2+1; printf("%d\n",max(len1,max(len2,len3))); } return 0;}
阅读全文
0 0
- Codeforces Round #425 (Div. 2)比赛总结
- Codeforces Round #426 (Div. 2)比赛总结
- Codeforces Round #428 (Div. 2)比赛总结
- Codeforces Round #431 (Div. 2)(有E题!)比赛总结
- 记录第一次Codeforces Round #250 (Div. 2)的比赛
- Codeforces Round #425 (Div. 2)
- Codeforces Round #425 (Div. 2)
- Codeforces Round #425 (Div. 2)
- Codeforces Round #425 (Div.2)
- Codeforces Round #425 (Div. 2)
- Codeforces Round #425 (Div. 2)
- Codeforces Round #161 (Div. 2)总结
- Codeforces Round #162 (Div. 2)总结
- Codeforces Round #170 (Div. 2)总结
- Codeforces Round #171 (Div. 2)总结
- Codeforces Round #172 (Div. 2)总结
- Codeforces Round #173 (Div. 2)总结
- Codeforces Round #176 (Div. 2)总结
- 根据条件控制Grid列能否编辑
- RESTful笔记
- 正则表达式入门
- Leetcode: Binary Tree Zigzag Level Order Traversal
- 多校联合赛第二场Mammum Sequence(贪心)
- Codeforces Round #425 (Div. 2)比赛总结
- svn
- JavaSE异常类
- 函数的调用过程
- HTML5中的Workers多线程处理
- 对象转型
- 访问同一域名,手机端跳转不同链接
- Linux 字符截取命令
- LeetCode 168 Excel Sheet Column Title