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. java之 惰性初始化

    class Soap { private String s; Soap(){ System.out.println("Soap()"); s="Constructed&q ...

  2. 【Linux常见命令】echo命令

    echo - display a line of text 打印输出内容的常用命令,可以结合重定向>和追加>>对文件进行覆盖或追加内容. 语法: echo [SHORT-OPTION ...

  3. 记一次痛苦的Django报错调试经历:

    开发的程序在我的本地mac上,ubuntu上,以及树莓派上都成功实现了迁移和运行,但是当准备将运行好好地程序迁移到阿里云的服务器上的mysql数据库上时,出现了非常多的幺蛾子的问题. 具体如下: 初始 ...

  4. 如何创建和部署自己的EOS代币

    本文我们将弄清楚什么是EOS代币以及如何自己创建和部署EOS代币. 与以太坊相反,EOS带有即插即用的代币智能合约.以太坊拥有ERC20智能合约,EOS拥有eosio.token智能合约.Eosio. ...

  5. 解决w3wp.exe占用CPU和内存问题

    在WINDOWS2003+IIS6下,经常出现w3wp的内存占用不能及时释放,从而导致服务器响应速度很慢.可以做以下配置进行改善:1.在IIS中对每个网站进行单独的应用程序池配置.即互相之间不影响.2 ...

  6. Cobbler自动装机试验

    Cobbler自动装机简介:Cobbler是一个使用Python开发的开源项目,通过将部署系统所涉及的所有服务集中在一起,来提供一个全自动的批量快速建立Linux系统的网络安装环境.Cobbler提供 ...

  7. 用数据说话,R语言有哪七种可视化应用?

    今天,随着数据量的不断增加,数据可视化成为将数字变成可用的信息的一个重要方式.R语言提供了一系列的已有函数和可调用的库,通过建立可视化的方式进行数据的呈现.在使用技术的方式实现可视化之前,我们可以先和 ...

  8. 搭建vsftpd文件服务器并创建虚拟用户

    一.安装     1. 查看是否安装vsftpd         rpm -qa | grep vsftpd     2. 安装          yum -y install vsftpd      ...

  9. FTP服务器项目的一些整理

    几个月前按照网上的教程写了一个FTP的服务器,现在回头整理一下里面的一些知识. FTP简介 FTP是文件传输协议(File Transfer Protocol),工作在TCP/IP协议族的应用层,其传 ...

  10. win10 手动安装mysql-8.0.11-winx64.zip

    0.彻底删除win10上安装的mysql(转载 : https://www.cnblogs.com/jpfss/p/6652701.html) 1.去官网下载mysql-8.0.11-winx64.z ...