哈理工新生赛 马拉车+贪心 最大密度子图 AC自动机+DP
J.Symmys | |||||
|
|||||
Description | |||||
ClearY is not good at English. He often fails in his English test. To help him study English, his English teacher asks him to rewrite some sentence. But ClearY doesn’t want to rewrite; he wants to play games. He comes up with a solution to complete rewriting earlier. He uses both his hands to write but he can only write the same letter at the same time. Every time, he chooses a symmetry center, using his left hand writing from this position to left continually and using his right hand writing from this position to right continually. He doesn’t not care about writing same letter two or more times in one place. He wants to know how many symmetry center at least he need to choose to complete his work. |
|||||
Input | |||||
First line contains an integer T (1 ≤ T ≤ 1000), represents there are T test cases. For each test case: one line contains a string of up to 106 lower case letters in length. It’s guaranteed that the sum length of all string will not exceed 5*106. |
|||||
Output | |||||
For each test case, output one line containing "Case #X: Y"(without quotes), where X is the case number starting from 1, and Y is the minimum number of symmetry center at least ClearY need to choose. |
|||||
Sample Input | |||||
2 aba abbaab |
|||||
Sample Output | |||||
Case #1: 1 Case #2: 2 |
|||||
Hint | |||||
For the second sample case, he can write "abba"(position from 1 to 4) and "baab"(position from 3 to 6). |
#include<cstdio>//踩坑 for循环里不能每次求strlen
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=1e6+;
char str[N],t[N<<];
int p[N<<];
void Manacher(){
t[]='$',t[]='#';
int tot=;
int tc=strlen(str);
for(int i=;i<tc;++i) t[tot++]=str[i],t[tot++]='#';
t[tot]=;
tc=strlen(t);
int mx=,id=;
for(int i=;i<tc;++i) {
p[i]=mx>i?min(p[*id-i],mx-i):;
while(t[i+p[i]]==t[i-p[i]]) ++p[i];
if(mx<i+p[i]) {
mx=i+p[i];
id=i;
}
}
}
int maxx[N<<];
int main(){
int cas=,T;
for(scanf("%d",&T);T--;){
scanf("%s",str);
Manacher();
int tot=,length=*strlen(str)+;
for(int i=;i<=length;++i) maxx[i]=;
for(int i=;i<=length;++i) maxx[i-p[i]+]=max(maxx[i-p[i]+],i+p[i]);
int l=,sum=,mx=;
for(int i=;i<=length;++i) maxx[i]=max(maxx[i-],maxx[i]);
while(l<=length) {
l=maxx[l];
++sum;
}
printf("Case #%d: %d\n",cas++,sum);
}
}
F.GXZ is poison | |||||
|
|||||
Description | |||||
GXZ is a famous ACMer, and he is very strong and poisonous. His most powerful weapons are some poisonous strings, which will make your code full of bugs. Now there is a code, your task is to make them healthy, which means you are to repair your code by changing least number of characters so that the code doesn't contain any poisonous strings. To make it simpler, let's define "code" as a string composed of three characters: "G", "X", "Z". |
|||||
Input | |||||
The input consists of multiple (at most 10) test cases. Each test case starts with a line containing one integers N (1 ≤ N ≤ 50), which is the number of poisonous strings. The following N lines gives N non-empty strings of length not greater than 20 containing only characters in "GXZ", which are the poisonous strings. The last line of the test case is a non-empty string of length not greater than 1000 containing only characters in "GXZ", which is the code to be repaired. |
|||||
Output | |||||
For each test case, print a line containing the test case number (beginning with 1) followed by the number of characters which need to be changed. If it's impossible to repair the given code, print -1. |
|||||
Sample Input | |||||
2 GGG GGX GGGX 2 G ZX ZXGGZX 3 G X Z GXZ |
|||||
Sample Output | |||||
Case 1: 1 Case 2: 4 Case 3: -1 |
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
char str[N];
int dp[N][N],cas=;
struct AC{
int ch[N][],fail[N],sz,rt;
bool flag[N];
void init(){
sz=rt=;
memset(ch[rt],-,sizeof(ch[rt]));
flag[rt]=;
}
void newnode(){
++sz;
for(int i=;i<;++i) ch[sz][i]=-;
flag[sz]=;
}
void insert(char *str){
int len=strlen(str);
int u=rt;
for(int i=;i<len;++i) {
int zc;
if(str[i]=='G') zc=;
else if(str[i]=='X') zc=;
else zc=;
if(ch[u][zc]==-) {
newnode();
ch[u][zc]=sz;
}
u=ch[u][zc];
}
flag[u]=;
}
void build(){
queue<int>Q;
for(int i=;i<;++i) {
if(ch[rt][i]==-) ch[rt][i]=rt;
else {
fail[ch[rt][i]]=rt;
Q.push(ch[rt][i]);
}
}
while(!Q.empty()) {
int u=Q.front();
Q.pop();
flag[u]|=flag[fail[u]];
for(int i=;i<;++i) {
if(ch[u][i]==-) ch[u][i]=ch[fail[u]][i];
else {
fail[ch[u][i]]=ch[fail[u]][i];
Q.push(ch[u][i]);
}
}
}
}
void DP(){
memset(dp,-,sizeof(dp));
dp[][]=;
for(int i=;str[i-];++i) for(int j=;j<=sz;++j) if(!flag[j]&&dp[i-][j]!=-)
for(int k=;k<;++k) {
if(flag[ch[j][k]]) continue;
if(str[i-]=='G'&&k==||str[i-]=='X'&&k==||str[i-]=='Z'&&k==) {
if(dp[i][ch[j][k]]==-) dp[i][ch[j][k]]=dp[i-][j];
else dp[i][ch[j][k]]=min(dp[i][ch[j][k]],dp[i-][j]);
}
else {
if(dp[i][ch[j][k]]==-) dp[i][ch[j][k]]=dp[i-][j]+;
else dp[i][ch[j][k]]=min(dp[i][ch[j][k]],dp[i-][j]+);
}
}
int ans=0x3f3f3f3f,len=strlen(str);
for(int i=;i<=sz;++i) if(dp[len][i]!=-) ans=min(ans,dp[len][i]);
printf("Case %d: %d\n",cas++,ans==0x3f3f3f3f?-:ans);
}
}ac;
int main(){
int n;
while(scanf("%d",&n)!=EOF){
ac.init();
for(int i=;i<=n;++i) {
scanf("%s",str);
ac.insert(str);
}
ac.build();
scanf("%s",str);
ac.DP();
}
}
C.Getting More Money Early | |||||
|
|||||
Description | |||||
There is an airline company. They accidentally found a new country with N cities. They want to build some airlines. But, before you have an airline, the start city and the end city must had built an airport. Building an airport need P unit(s) money. And the company has got the information that how much money a year some airline can earn. So, they would like to get profit as early as possible. Can you tell the company's director the earliest time they can start to get profits? But,we may get a decimal number. So, you just need to print the sum of the investment and the sum of profit in one year in the condition above. |
|||||
Input | |||||
The first line contains an integer T (1 ≤ T ≤ 5), represents the number of test cases. For each test case: The first line contains three integers N, M, P (1 ≤ N ≤ 500, 1 ≤ M ≤ 1000, 1 ≤ P ≤ 1000) Each line of the following M lines three integers, ui, vi, pi(1 ≤ ui, vi ≤ N, ui != vi,1 ≤ pi ≤ 1000), which means the airline between ui and vi city, and the profit the airline can get each year. The data promise that the number of airlines between any two cities is less than or equal to one. |
|||||
Output | |||||
For each test case, output one line containing "Case #X: "(without quotes) at first, where X is the case number starting from 1. Than print the answer of the two number we need. The first is the sum of the investment and the second is the profit the company can get every year in that condition. |
|||||
Sample Input | |||||
1 5 6 4 1 5 3 5 4 1 4 2 2 2 5 4 1 2 1 3 1 5 |
|||||
Sample Output | |||||
Case #1: 16 13 |
|||||
Hint | |||||
Case 1: you can choose city 1,2,3,5 and cost 16 unit of money and you can get the profit from the 1.23 year. That is the earliest time the company can start to get profit. |
这题被卡精度。。先扔坑
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=;
const double eps=1e-;
const double INF=1e9+;
int n,m,head[N],tot,dis[N],S,T,q[N];
double p;
struct node{
int v,next;
double w;
}e[N<<];
struct py{
int u,v;
double val;
}ct[N];
void add(int u,int v,double w){
e[tot].v=v;e[tot].w=w;e[tot].next=head[u];head[u]=tot++;
}
bool bfs(){
for(int i=S;i<=T;++i) dis[i]=-;
dis[S]=;
int l=,r=;
q[r++]=S;
while(l<r) {
int u=q[l++];
for(int i=head[u];~i;i=e[i].next){
int v=e[i].v;
if(dis[v]==-&&e[i].w>eps) {
q[r++]=v;
dis[v]=dis[u]+;
if(v==T) return true;
}
}
}
return false;
}
double dfs(int s,double low){
if(s==T||low<eps) return low;
double ans=low,a;
for(int i=head[s];~i;i=e[i].next) {
if(e[i].w>&&dis[e[i].v]==dis[s]+){
a=dfs(e[i].v,min(e[i].w,ans));
if(a<eps) continue;
e[i].w-=a;
e[i^].w+=a;
ans-=a;
if(ans<eps) return low;
}
}
if(low-ans<eps) dis[s]=-;
return low-ans;
}
int main(){
int cas=,Ta;
for(scanf("%d",&Ta);Ta--;){
scanf("%d%d%lf",&n,&m,&p);
S=,T=n+m+;
double ans=;
for(int i=;i<=m;++i) scanf("%d%d%lf",&ct[i].u,&ct[i].v,&ct[i].val),ans+=ct[i].val;
double l=,r=1e6+;
for(int i=;i<;++i){
double mid=(l+r)/;
for(int i=;i<=n+m+;++i) head[i]=-;
tot=;
for(int i=;i<=m;++i) {
add(S,i,ct[i].val),add(i,S,);
add(i,ct[i].u+m,INF),add(ct[i].u+m,i,);
add(i,ct[i].v+m,INF),add(ct[i].v+m,i,);
}
double ret=;
for(int i=;i<=n;++i) add(i+m,T,mid*p),add(T,i+m,);
while(bfs()) ret+=dfs(S,INF);
if(ans-ret<=eps) r=mid;
else l=mid;
}
l-=eps;
double ying=,tt=;
for(int i=head[T];~i;i=e[i].next) if(l*p-e[i].w<=eps) tt+=p;
ying=tt*l;
int y=round(ying),t=round(tt);
printf("Case #%d: %d %d\n",cas++,t,y);
}
}
哈理工新生赛 马拉车+贪心 最大密度子图 AC自动机+DP的更多相关文章
- HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)
Walk Through Squares Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- 2018 焦作网络赛 L Poor God Water ( AC自动机构造矩阵、BM求线性递推、手动构造矩阵、矩阵快速幂 )
题目链接 题意 : 实际上可以转化一下题意 要求求出用三个不同元素的字符集例如 { 'A' .'B' .'C' } 构造出长度为 n 且不包含 AAA.BBB CCC.ACB BCA.CAC CBC ...
- 6.29 省选模拟赛 坏题 AC自动机 dp 图论
考场上随手构造了一组数据把自己卡掉了 然后一直都是掉线状态了. 最后发现这个东西不是subtask -1的情况不多 所以就没管无解直接莽 写题有点晚 故没调出来.. 考虑怎么做 容易想到建立AC自动机 ...
- SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告
题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音? ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- POJ 3155 Hard Life(最大密度子图)
裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...
- poj 3155 最大密度子图
思路: 这个还是看的胡伯涛的论文<最小割在信息学竞赛中的应用>.是将最大密度子图问题转化为了01分数规划和最小割问题. 直接上代码: #include <iostream> # ...
- UVA LA 7146 2014上海亚洲赛(贪心)
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...
- POJ3155 Hard Life [最大密度子图]
题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...
随机推荐
- Forrester:开源APM发展势头强劲
在企业的运营团队看来,系统的稳定性和可靠运行时间是至关重要的.因此,企业更乐意向能够负责的技术提供商购买开发完整的.有文档记录的,并且有售后支持的工具或软件. 一般来说,运营团队没有额外精力来应付新奇 ...
- JeeSite 4.0 简化业务逻辑层开发
2019独角兽企业重金招聘Python工程师标准>>> 引言 对于业务逻辑层的开发重复代码很多,尽管有代码生成器,但从代码量总的来说还是比较多,所以就有了以下抽象类及工具,对一些常用 ...
- IEEE 754标准--维基百科
IEEE二进制浮点数算术标准(IEEE 754) 是20世纪80年代以来最广泛使用的浮点数运算标准,为许多CPU与浮点运算器所采用.这个标准定义了表示浮点数的格式(包括负零-0)与反常值(denorm ...
- P1465 序言页码 Preface Numbering (手推)
题目描述 一类书的序言是以罗马数字标页码的.传统罗马数字用单个字母表示特定的数值,以下是标准数字表: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 最多3个同样的可以表示为 ...
- django源码分析——静态文件staticfiles中间件
本文环境python3.5.2,django1.10.x系列 1.在上一篇文章中已经分析过handler的处理过程,其中load_middleware就是将配置的中间件进行初始化,然后调用相应的设置方 ...
- Git 向远端仓库推文件
第一次推送: 1.git init (创建本地仓库) 2. git remote add origin <远端仓库地址> (与远端仓库建立链接) 3.git checkout -b < ...
- 简单谈谈Spring的IoC
一.前言 这几天正在复习Spring的相关内容,同时想要对Spring的实现原理做一些深入的研究.今天看了看Spring中IoC的实现,找到了一篇非常详细的博客,研究了一个下午,看完之后唯一的感受 ...
- 用Visual Studio2019自定义项目模板
项目模板简介 众所周知,在我们使用VS新建项目时,都需要选择一个项目模板,如下图: 我们选择完项目模板进行创建,创建完成之后,可以发现项目中已经包含了一些基础的文件.例如MVC: 可以看到,MVC项目 ...
- Day_10【常用API】扩展案例2_获取输入日期是哪一年的哪一天的星期几
分析以下需求,并用代码实现 1)已知日期字符串:"2015-10-20",将改日期字符串转换为日期对象 2)将(1)中的日期对象转换为日历类的对象 3)根据日历对象获取改日期是星期 ...
- Web快速输入标签
在书写web代码的时候,掌握一些快捷输入方式不仅可以提高效率,还能省不少力气. 1. > :下一个子标签,如 div>p 加Tab达到: <div><p></ ...