J.Symmys
Time Limit: 1000 MS Memory Limit: 262144 K
Total Submit: 50 (13 users) Total Accepted: 2 (2 users) Special Judge: No
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
Time Limit: 1000 MS Memory Limit: 262144 K
Total Submit: 14 (5 users) Total Accepted: 0 (0 users) Special Judge: No
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
Time Limit: 1000 MS Memory Limit: 262144 K
Total Submit: 10 (6 users) Total Accepted: 0 (0 users) Special Judge: No
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的更多相关文章

  1. 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 ...

  2. 2018 焦作网络赛 L Poor God Water ( AC自动机构造矩阵、BM求线性递推、手动构造矩阵、矩阵快速幂 )

    题目链接 题意 : 实际上可以转化一下题意 要求求出用三个不同元素的字符集例如 { 'A' .'B' .'C' } 构造出长度为 n 且不包含 AAA.BBB CCC.ACB BCA.CAC CBC ...

  3. 6.29 省选模拟赛 坏题 AC自动机 dp 图论

    考场上随手构造了一组数据把自己卡掉了 然后一直都是掉线状态了. 最后发现这个东西不是subtask -1的情况不多 所以就没管无解直接莽 写题有点晚 故没调出来.. 考虑怎么做 容易想到建立AC自动机 ...

  4. SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告

            题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音?       ...

  5. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  6. POJ 3155 Hard Life(最大密度子图)

    裸题.输入一个无向图,输出最大密度子图(输出子图结点数和升序编号). 看了<最小割模型在信息学竞赛中的应用——胡伯涛>的一部分,感觉01分数规划问题又是个大坑.暂时还看不懂. 参考http ...

  7. poj 3155 最大密度子图

    思路: 这个还是看的胡伯涛的论文<最小割在信息学竞赛中的应用>.是将最大密度子图问题转化为了01分数规划和最小割问题. 直接上代码: #include <iostream> # ...

  8. UVA LA 7146 2014上海亚洲赛(贪心)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...

  9. POJ3155 Hard Life [最大密度子图]

      题意:最大密度子图 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

随机推荐

  1. gitlab环境部署

    一:配置主机名 [root@localhost ~]# hostname gitlab[root@localhost ~]# bash 二:安装依赖包 [root@gitlab ~]# yum -y ...

  2. Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError

    Django中修改DATABASES后,执行python manage.py ****报错!UnicodeEncodeError: 'latin-1' codec can't encode chara ...

  3. TEC-004-php文件下载任意文件读取漏洞修复

    修改download?u参数值,将/public/files/14842030529.txt,替换为../../../../../../../../../../etc/passwd    functi ...

  4. Java反射与注解

    反射 能够分析类能力的程序称为反射(reflective),代码的这种能力称为"自省".反射机制的功能极其强大,反射机制可以用来: 在运行时分析类的能力 在运行时查看对象,例如,编 ...

  5. MySQL - Show Global Status 整理

    2019独角兽企业重金招聘Python工程师标准>>> MySQL - Show Global Status 整理 原文来源:MySQL 5.5 Reference Manual 部 ...

  6. MySQL重新初始化安装数据库

     删除./mysql/var下的所有数据后,怎么重新安装初始数据库? (1)进入./mysql/bin目录下,执行脚本./mysql_install_db: (2)执行完(1)后,此时会在./mysq ...

  7. 批量将制定文件夹下的全部Excel文件导入微软SQL数据库

    以下代码将c:\cs\文件夹下的全部Excle中数据导入到SQL数据库 declare @query vARCHAR(1000) declare @max1 int declare @count1 i ...

  8. Jdbc批处理一点异同

    同样的代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 public class TestBatch {   public stati ...

  9. 【漏洞预警】SaltStack远程命令执行漏洞 /tmp/salt-minions

    前言:   2020年5月3日,阿里云应急响应中心监测到近日国外某安全团队披露了SaltStack存在认证绕过致命令执行漏洞以及目录遍历漏洞.在多个微信群和QQ群已经有群友反映中招,请马上修复. 以下 ...

  10. sqlserver2005定期备份和清除

    1.打开管理->维护计划 2.右键点击新建维护计划 3.给新的维护计划自定义命名 4.可以看左下角的维护方式 5.拖动“备份数据库”到右边 6.选中,编辑备份方式 7.选择备份方式,所有数据库, ...