CodeForces 828C【构造】
来源:互联网 发布:2016年淘宝全年销售额 编辑:程序博客网 时间:2024/05/01 18:30
题意:
给你N个串,然后给出每个串在所求串的起始位置,让你求这个串,并且保证字典序最小。
思路:
读完题发现!怎么那么简单???
我想的就是对每个位置记录以该位置为起点的最长串,记录输入ID和长度。
然后队友说你串怎么存啊?
String啊???
会超时么???
不知道…
然后具体写的时候,发现在构造的时候,比如(以该位置为起点的最长串的长度):
46
代表第0位置起始是4长度,到了第1位置起始是6长度,在构造到第1位置的时候要以第1位置起点串来构造。具体我写了个DFS。
队友代码 T 了,死于cin,然后发现字符串不要一个一个字符输出,慢。
其实对于这种判断不好输入的难道不应该写个“输入挂”??
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N=1e7+10;int len[N];string ss[100010];struct asd{ int pos; int id;}q[N];bool vis[N];int Max;char s[N], ans[N];void DFS(int x){ int temp; int pp; pp = x + len[x] - 1;// printf("%d %d\n",x, pp); for(int i=x,k = 0;i<=pp;i++, k++){ temp = i + len[i] - 1; if(temp > pp){ DFS(i); break; } vis[i] = true; ans[i] = ss[q[x].id][k]; }}int main(){ Max = 0; memset(len,0,sizeof(len)); int n, temp, k, x; scanf("%d",&n); for(int i=0;i<n;i++){ cin>>ss[i]; temp = ss[i].length(); scanf("%d",&k); for(int j=0;j<k;j++){ scanf("%d", &x); x--; if(temp > len[x]){ len[x] = temp; q[x].pos = temp; q[x].id = i; Max = max(x + temp - 1, Max); } } }// for(int i=0;i<=Max;i++)// {// printf("%d ",len[i]);// }// puts("");// printf("%d\n",Max); memset(vis, false, sizeof(vis)); for(int i = 0; i<= Max;i++){ if(vis[i]) continue; DFS(i); } for(int i=0;i<=Max;i++){ if(vis[i]) printf("%c",ans[i]); else printf("a"); } puts(""); return 0;}
阅读全文
0 0
- CodeForces 828C【构造】
- CodeForces 600C【构造】
- CodeForces 110C 【构造】
- Codeforces 141C【构造】
- Codeforces 862C(构造)
- Codeforces 417C Football(构造)
- Codeforces 489C 简单构造
- [构造]CodeForces 613C Necklace
- Codeforces 141C Queue 【构造】
- codeforces 740C mex 构造
- Codeforces 487C 数论+构造
- CodeForces-707c[数学构造]
- Codeforces 398C Tree and Array(构造)
- Codeforces 346C Number Transformation II 构造
- CodeForces 21C Stripe 2 构造题
- CodeForces 26C Parquet 构造题
- Codeforces 459C Pashmak and Buses(构造)
- Codeforces 362C. Insertion Sort【构造】
- 据说这是国外最火的55套PS实用教程!
- CSS背景、尺寸、显示、盒子模型以及元素的定位
- HDU 2063
- Python
- 基于 {@link EntityManager} 的数据库操作方法集
- CodeForces 828C【构造】
- [NOIP2016]天天爱跑步
- ACM各种有用的模板
- 映射与反射
- dubbo直连
- 模型生成过程中检测到一个或多个验证错误
- iTOP4412 安装tftp服务器
- 为什么施诺尔签名有助解决今天比特币的两大难题
- 阅读器也能个性化?屏保加密换字体,掌阅一个都不少