hdu 6103 Kirinriki

#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char s[];
void doit(int l,int r)
{
int d=,nw=;
for(;l<r;l++,r--)
{
while(l+d<r-d&&nw+abs(s[l+d]-s[r-d])<=m)nw+=abs(s[l+d]-s[r-d]),d++;
ans=max(ans,d);
nw-=abs(s[l]-s[r]);
d--;
}
}
void sol()
{
scanf("%d%s",&m,s);
n=strlen(s);
ans=;
for(int i=n-;i>=;i--)doit(,i);
for(int i=;i<n-;i++)doit(i,n-);
printf("%d\n",ans);
}
int main()
{
int tt;scanf("%d",&tt);
while(tt--)sol();
return ;
}

hdu 6035 Colorful Tree

#include<bits/stdc++.h>
using namespace std;
int n,cc,cs,cnt[],vis[],c[],sz[];
long long ans,res;
vector<int>g[];
void dfs(int x,int p)
{
sz[x]=;
int ss=;
for(int i=;i<g[x].size();i++)if(g[x][i]!=p)
{
int lst=cnt[c[x]];
dfs(g[x][i],x);
sz[x]+=sz[g[x][i]];
int nw=cnt[c[x]]-lst;
ss+=nw;
nw=sz[g[x][i]]-nw;
res+=1ll*nw*(nw-)/;
}
cnt[c[x]]+=sz[x]-ss;
}
void sol()
{
cc=;
memset(vis,,sizeof(vis));
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++)scanf("%d",&c[i]),vis[c[i]]=;
for(int i=;i<=n;i++)if(vis[i])cc++;
for(int i=;i<=n;i++)g[i].clear();
for(int i=;i<n;i++){int u,v;scanf("%d%d",&u,&v);g[u].push_back(v);g[v].push_back(u);}
res=;
dfs(,);
ans=1ll*n*(n-)/*cc;
for(int i=;i<=n;i++)if(vis[i])
{
int sz=n-cnt[i];
res+=1ll*sz*(sz-)/;
}
ans-=res;
printf("Case #%d: %lld\n",++cs,ans);
}
int main()
{
while(scanf("%d",&n)==)sol();
return ;
}

hdu 6071 Lazy Running

#include<bits/stdc++.h>
using namespace std;
long long k,a,b,c,dd,d[][];
vector<pair<long long,int> >g[];
void sol()
{
scanf("%lld%lld%lld%lld%lld",&k,&a,&b,&c,&dd);
long long w=*min(a,b);
for(int i=;i<=;i++)g[i].clear();
g[].push_back(make_pair(,a));
g[].push_back(make_pair(,a));
g[].push_back(make_pair(,b));
g[].push_back(make_pair(,b));
g[].push_back(make_pair(,c));
g[].push_back(make_pair(,c));
g[].push_back(make_pair(,dd));
g[].push_back(make_pair(,dd));
memset(d,0x3f,sizeof(d));
d[][]=;
queue<pair<int,int> >q;
q.push(make_pair(,));
while(!q.empty())
{
long long l=q.front().first,x=q.front().second;
q.pop();
for(int i=;i<;i++)if(d[g[x][i].first][(l+g[x][i].second)%w]>l+g[x][i].second)
{
d[g[x][i].first][(l+g[x][i].second)%w]=l+g[x][i].second;
q.push(make_pair(l+g[x][i].second,g[x][i].first));
}
}
long long ans=2e18;
for(int i=;i<w;i++)if(d[][i]>k)ans=min(ans,d[][i]);else ans=min(ans,d[][i]+(k-d[][i]+w-)/w*w);
printf("%lld\n",ans);
}
int main()
{
int tt;cin>>tt;
while(tt--)sol();
return ;
}

hdu 6073 Matching in Multiplication

#include<bits/stdc++.h>
using namespace std;
const int md=;
int n,vis[];
vector<pair<int,int> >g[];
vector<int>e,t;
void sol()
{
scanf("%d",&n);
for(int i=;i<=n*;i++)vis[i]=,g[i].clear();
for(int i=;i<=n;i++)
{
int u,wu,v,wv;
scanf("%d%d%d%d",&u,&wu,&v,&wv);
g[i].push_back(make_pair(n+u,wu));
g[n+u].push_back(make_pair(i,wu));
g[i].push_back(make_pair(n+v,wv));
g[n+v].push_back(make_pair(i,wv));
}
bool f=false;
for(int i=;i<=n;i++)if(!g[n+i].size())f=true;
if(f){printf("0\n");return;}
int ans=;
for(int i=n+;i<=*n;i++)if(g[i].size()==&&!vis[i])
{
int res=g[i][].second,lst=i,nw=g[i][].first;
while(true)
{
vis[lst]=;vis[nw]=;
int nxt=g[nw][].first+g[nw][].first-lst;
if(g[nxt].size()==)res=;
if(g[nxt].size()!=)
{
int j;
for(j=;j<g[nxt].size();j++)if(g[nxt][j].first==nw)break;
g[nxt].erase(g[nxt].begin()+j);
break;
}
lst=nxt;
nw=g[nxt][].first+g[nxt][].first-nw;
int cc=(g[lst][].first==nw)?g[lst][].second:g[lst][].second;
res=1ll*res*cc%md;
}
ans=1ll*ans*res%md;
}
for(int i=;i<=*n;i++)if(g[i].size()==&&!vis[i])
{
e.clear();t.clear();
e.push_back(i);e.push_back(g[i][].first);
t.push_back(g[i][].second);
int lst=i,nw=g[i][].first;
vis[lst]=;
while(true)
{
vis[nw]=;
int nxt=g[nw][].first+g[nw][].first-lst;
int cc=(g[nw][].first==nxt)?g[nw][].second:g[nw][].second;
t.push_back(cc);
if(vis[nxt])break;
lst=nw;nw=nxt;e.push_back(nw);
}
int res1=,res2=;
for(int i=;i<t.size();i+=)res1=1ll*res1*t[i]%md;
for(int i=;i<t.size();i+=)res2=1ll*res2*t[i]%md;
res1=(res1+res2)%md;
ans=1ll*ans*res1%md;
}
printf("%d\n",ans);
}
int main()
{
int tt;scanf("%d",&tt);
while(tt--)sol();
return ;
}

hdu 6070 Dirt Ratio

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-;
struct st{double mn,tg;}seg[];
int n,a[],ps[];
void up(int x){seg[x].mn=min(seg[x<<].mn,seg[x<<|].mn);}
void down(int x)
{
seg[x<<].mn+=seg[x].tg;
seg[x<<].tg+=seg[x].tg;
seg[x<<|].mn+=seg[x].tg;
seg[x<<|].tg+=seg[x].tg;
seg[x].tg=;
}
void build(int x,int l,int r)
{
seg[x]=(st){,};
if(l==r)return;
int md=l+r>>;build(x<<,l,md);build(x<<|,md+,r);
}
void modify(int x,int l,int r,int tl,int tr,double v)
{
if(tl<=l&&r<=tr){seg[x].mn+=v,seg[x].tg+=v;return;}
if(seg[x].tg)down(x);
int md=l+r>>;
if(tl<=md)modify(x<<,l,md,tl,tr,v);
if(tr>md)modify(x<<|,md+,r,tl,tr,v);
up(x);
}
double query(int x,int l,int r,int tl,int tr)
{
if(tl<=l&&r<=tr)return seg[x].mn;
if(seg[x].tg)down(x);
int md=l+r>>;double ans=1e9;
if(tl<=md)ans=min(ans,query(x<<,l,md,tl,tr));
if(tr>md)ans=min(ans,query(x<<|,md+,r,tl,tr));
return ans;
}
bool chk(double x)
{
build(,,n);
memset(ps,,sizeof(ps));
for(int i=;i<=n;i++)
{
modify(,,n,ps[a[i]]+,i,);
modify(,,n,,i,-x);
if(query(,,n,,i)<=)return true;
ps[a[i]]=i;
}
return false;
}
int main()
{
int tt;scanf("%d",&tt);
while(tt--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
double l=,r=,ans=;
while(r-l>=eps)
{
double md=(l+r)/2.0;
if(chk(md))ans=md,r=md;else l=md;
}
printf("%.6f\n",ans);
}
return ;
}

hdu 6078 Wavel Sequence

#include<bits/stdc++.h>
using namespace std;
const long long md=998244353ll;
int n,m,a[],b[];
long long dp[][];
void sol()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)scanf("%d",&a[i]);
for(int i=;i<m;i++)scanf("%d",&b[i]);
long long ans=;
memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
{
long long s1=,s2=;//·å£¬¹È
for(int j=;j<m;j++)
{
if(a[i]>b[j])dp[][j]=(dp[][j]+s1)%md;
else if(a[i]<b[j])dp[][j]=(dp[][j]+s2)%md;
else
{
s1=(s1+dp[][j])%md;
s2=(s2+dp[][j]+)%md;
}
}
ans=(ans+s1+s2)%md;
}
printf("%lld\n",ans);
}
int main()
{
int tt;scanf("%d",&tt);
while(tt--)sol();
return ;
}

hdu some problems in Multi-University Training Contest的更多相关文章

  1. hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...

  2. HDU 6143 - Killer Names | 2017 Multi-University Training Contest 8

    /* HDU 6143 - Killer Names [ DP ] | 2017 Multi-University Training Contest 8 题意: m个字母组成两个长为n的序列,两序列中 ...

  3. HDU 6074 - Phone Call | 2017 Multi-University Training Contest 4

    看标程的代码这么短,看我的.... 难道是静态LCA模板太长了? /* HDU 6074 - Phone Call [ LCA,并查集 ] | 2017 Multi-University Traini ...

  4. HDU 6068 - Classic Quotation | 2017 Multi-University Training Contest 4

    /* HDU 6068 - Classic Quotation [ KMP,DP ] | 2017 Multi-University Training Contest 4 题意: 给出两个字符串 S[ ...

  5. HDU 6076 - Security Check | 2017 Multi-University Training Contest 4

    /* HDU 6076 - Security Check [ DP,二分 ] | 2017 Multi-University Training Contest 4 题意: 给出两个检票序列 A[N], ...

  6. HDU 6071 - Lazy Running | 2017 Multi-University Training Contest 4

    /* HDU 6071 - Lazy Running [ 建模,最短路 ] | 2017 Multi-University Training Contest 4 题意: 四个点的环,给定相邻两点距离, ...

  7. HDU 6078 - Wavel Sequence | 2017 Multi-University Training Contest 4

    /* HDU 6078 - Wavel Sequence [ DP ] | 2017 Multi-University Training Contest 4 题意: 给定 a[N], b[M] 要求满 ...

  8. HDU 6070 - Dirt Ratio | 2017 Multi-University Training Contest 4

    比赛时会错题意+不知道怎么线段树维护分数- - 思路来自题解 /* HDU 6070 - Dirt Ratio [ 二分,线段树 ] | 2017 Multi-University Training ...

  9. HDU 6036 - Division Game | 2017 Multi-University Training Contest 1

    /* HDU 6036 - Division Game [ 组合数学,NTT ] | 2017 Multi-University Training Contest 1 题意: k堆石子围成一个圈,数量 ...

  10. HDU 6039 - Gear Up | 2017 Multi-University Training Contest 1

    建模简析: /* HDU 6039 - Gear Up [ 建模,线段树,图论 ] | 2017 Multi-University Training Contest 1 题意: 给你n个齿轮,有些齿轮 ...

随机推荐

  1. GOROOT、GOPATH、GOBIN

    GOROOT golang安装路径. GOPATH GOPATH可以设置多个工程目录,linux下用冒号分隔(必须用冒号,fish shell的空格分割会出错),windows下用分号分隔,但是go ...

  2. 万恶之源 - Python模块二

    shelve 我们之前学了json和pickle模块 这些都是序列化的模块,咱们进行在讲一个序列化的东西 叫做shelve 你们肯定有个疑问,这个东西和那个类似为什么要讲.是因为这个模块比较简单的,并 ...

  3. create genil component

    https://help.sap.com/viewer/79ef8b1636dd492d8fd430d2d309b90f/MDG92_SP01/en-US/16a5115454744a18e10000 ...

  4. react 全局公共组件-----动态弹窗 (dialog)

    react 的时候,总是会用到弹窗,并且各种各样的,一般来说,组件层级嵌套之后,就会出现 z-index层级覆盖的问题 这个时候,就需要一个公共的弹出层,然后我们将需要展示的组件,放到弹出层里面 下面 ...

  5. xmlns:dubbo 路径错误

    It goes normal when change <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

  6. cocos2d-x JS 利用重复动作实现动画播放(实现倒计时)

    cocos2d-js: cc.delayTime() and cc.repeatForever() don't work together in cc.sequence() this.numm = 1 ...

  7. webpack使用七

    产品阶段的构建 目前为止,我们已经使用webpack构建了一个完整的开发环境.但是在产品阶段,可能还需要对打包的文件进行额外的处理,比如说优化,压缩,缓存以及分离CSS和JS. 对于复杂的项目来说,需 ...

  8. beego 初体验 - 环境搭建

    首先,安装go运行时和beego beego,在git bash 运行命令: go get github.com/beego/bee go get github.com/astaxie/beego g ...

  9. 水题 K

    输入4行全部由大写字母组成的文本,输出一个垂直直方图,给出每个字符出现的次数.注意:只用输出字符的出现次数,不用输出空白字符,数字或者标点符号的输出次数. Input输入包括4行由大写字母组成的文本, ...

  10. python遍历某一位置所有文件夹中的文件

    通过多次遍历达到找出所有文件的目的 import os rootdir=["d:/77"] c=[] for i in rootdir: for parent,dirnames,f ...