精神不佳,选择了在场外同步划水

没想到实际做起来手感还好,早知道就报名了……

该打

未完待续233

A. Andryusha and Socks

模拟,模拟大法好。注意每次是先判断完能不能收进柜子,再算桌子上的袜子数量的。

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int a[mxn],n;
int cnt[mxn];
int main(){
int i,j,x;
n=read();
int now=,ans=;
for(i=;i<=n*;i++){
x=read();
cnt[x]++;
now++;
if(cnt[x]==)cnt[x]=,now-=;
ans=max(ans,now);
}
printf("%d\n",ans);
return ;
}

A

B. The Meeting Place Cannot Be Changed

判能否到达,肯定是判走得最慢的那个人。

二分终点不知可不可行,我选择二分时间。在限定时间内假设所有的人都往左走,找最后一个,再假设所有人往右走,找最后一个。如果这两个“最后”可以相遇,该时间可行。

精度1e-8就T了,1e-7正合适

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
double ans=;
double tmL[mxn],tmR[mxn];
struct fri{
double w,v;
}f[mxn];
int cmp(fri a,fri b){
return a.w<b.w;
}
bool solve(double lim){
double ML=;
for(int i=;i<=n;i++){
double pos=f[i].v*lim+(double)f[i].w;
ML=min(ML,pos);
}
double MR=-;
for(int i=;i<=n;i++){
double pos=(double)f[i].w-f[i].v*lim;
MR=max(MR,pos);
}
if(ML-MR>=eps)return ;
return ;
}
int main(){
int i,j;
n=read();
for(i=;i<=n;i++){
f[i].w=read();
}
for(i=;i<=n;i++){
f[i].v=read();
}
sort(f+,f+n+,cmp);
double ans=;
double l=,r=;
while(r-l>=eps){
double mid=(l+r)/;
if(solve(mid)){
ans=mid;
r=mid;
}
else l=mid;
}
printf("%.10lf\n",ans);
return ;
}

B

C. Andryusha and Colored Balloons

直接DFS,根据父结点和当前结点已有的颜色,来判断子结点可以选什么颜色

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].nxt=hd[u];e[mct].v=v;hd[u]=mct;return;
}
int n;
int ans[mxn];
bool vis[mxn];int cnt=;
void DFS(int u,int fa){
int cho=;
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==fa)continue;
while(cho==ans[u] || cho==ans[fa])cho++;
ans[v]=cho;
if(!vis[cho]){
vis[cho]=;
cnt++;
}
cho++;
DFS(v,u);
}
return;
}
int main(){
int i,j,u,v;
n=read();
for(i=;i<n;i++){
u=read();v=read();
add_edge(u,v);
add_edge(v,u);
}
ans[]=;vis[]=;cnt++;
DFS(,);
printf("%d\n",cnt);
for(i=;i<=n;i++){
printf("%d ",ans[i]);
}
printf("\n");
return ;
}

C

D. Innokenty and a Football League

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:

  1. the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
  2. or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".

Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.

Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.

Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.

Output

It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

If there are multiple answers, print any of them.

Examples
input
2
DINAMO BYTECITY
FOOTBALL MOSCOW
output
YES
DIN
FOO
input
2
DINAMO BYTECITY
DINAMO BITECITY
output
NO
input
3
PLAYFOOTBALL MOSCOW
PLAYVOLLEYBALL SPB
GOGO TECHNOCUP
output
YES
PLM
PLS
GOG
input
3
ABC DEF
ABC EFG
ABD OOO
output
YES
ABD
ABE
ABO
Note

In the first sample Innokenty can choose first option for both clubs.

In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.

In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.

In the fourth example note that it is possible that the chosen short name for some club x is the same as the first option of another club yif the first options of x and y are different.

暴力+二分图匹配

脑补了网络流等各种奇怪的方法,然而没有什么头绪。

再看看数据范围,啊,暴力你好,网络流再见

首先O(N^2)找出所有按照第一种编码会冲突的队伍,强制它们使用第二种编码,且不可改变。

然后依次判断每支队伍选择的编码方式,这里用到类似匈牙利算法的调整方式,如果当前决策和之前的冲突,尝试DFS向前调整,如果没有可行方案就判NO

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
const int INF=1e9;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
map<string,int>mp;
string s1[],s2[];
int vis[mxn];
int cho[mxn];
int n,cnt;
int link[mxn];
bool DFS(int p){
if(cho[p]!= && !vis[mp[s1[p]]]){
vis[mp[s1[p]]]=;
if(!link[mp[s1[p]]] || DFS(link[mp[s1[p]]])){
link[mp[s1[p]]]=p;
cho[p]=;
return ;
}
}
if(!vis[mp[s2[p]]]){
vis[mp[s2[p]]]=;
if(!link[mp[s2[p]]] || DFS(link[mp[s2[p]]])){
link[mp[s2[p]]]=p;
cho[p]=;
return ;
}
}
return ;
}
int main(){
n=read();
int i,j;
for(i=;i<=n;i++){
cin>>s1[i]>>s2[i];
s1[i]=s1[i].substr(,);
s2[i]=s1[i].substr(,)+s2[i].substr(,);
if(!mp[s1[i]])mp[s1[i]]=++cnt;
if(!mp[s2[i]])mp[s2[i]]=++cnt;
}
for(i=;i<=n;i++){
memset(vis,,sizeof vis);
for(j=;j<=n;j++){
if(i==j)continue;
if(s1[i]==s1[j]){
cho[i]=;break;
}
}
if(!DFS(i)){
printf("NO\n");
return ;
}
}
printf("YES\n");
for(i=;i<=n;i++){
if(cho[i]==){
cout<<s2[i]<<endl;
}
else cout<<s1[i]<<endl;
}
return ;
}

D

E. Underground Lab

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.

The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.

Each clone can visit at most  vertices before the lab explodes.

Your task is to choose starting vertices and searching routes for the clones. Each route can have at most  vertices.

Input

The first line contains three integers nm, and k (1 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105, 1 ≤ k ≤ n) — the number of vertices and edges in the lab, and the number of clones.

Each of the next m lines contains two integers xi and yi (1 ≤ xi, yi ≤ n) — indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.

The graph is guaranteed to be connected.

Output

You should print k lines. i-th of these lines must start with an integer ci () — the number of vertices visited by i-th clone, followed by ci integers — indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.

It is guaranteed that a valid answer exists.

Examples
input
3 2 1
2 1
3 1
output
3 2 1 3
input
5 4 2
1 2
1 3
1 4
1 5
output
3 2 1 3
3 4 1 5
Note

In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.

In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.

DFS序 脑洞题

吼题,吼题。刚开始毫无头绪,然后注意到每个人可以走2n/k个结点。←也就是说,每个结点走两遍都足够了。

那么先找出图的生成树,然后处理出DFS序,让每个人按DFS序能走多远走多远,达到限制就再换一个人走,就可以了。

注意这种贪心法可能用不完所有的人就出解了,但实际上要输出所有人的行走方案。因为没有注意到这个,一直WA 7。

  ↑解决方案是让没有用到的人都输出1 1(待在原地)

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt;
}e[mxn];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;return;
}
int n,m,k,lim;
int ans[mxn],cnt=;
vector<int>ve[mxn];
int fa[mxn];
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void upd(int u){
if(ans[cnt]<lim){
ans[cnt]++;
ve[cnt].push_back(u);
}
else{
++cnt;ans[cnt]++;
ve[cnt].push_back(u);
}
return;
}
void DFS(int u,int ff){
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==ff)continue;
upd(u);
DFS(v,u);
}
upd(u);
return;
}
int main(){
int i,j,u,v;
n=read();m=read();k=read();
lim=(*n+k-)/k;
for(i=;i<=n;i++)fa[i]=i;
for(i=;i<=m;i++){
u=read();v=read();
int fu=find(u),fv=find(v);
if(fu!=fv){
add_edge(u,v);
add_edge(v,u);
fa[fu]=fv;
}
}
cnt=;
DFS(,);
for(i=;i<=k;i++){
if(!ans[i]){
printf("1 1\n");
continue;
}
printf("%d ",ans[i]);
for(j=;j<ve[i].size();j++){
printf("%d ",ve[i][j]);
}
printf("\n");
}
return ;
}

E

F. Axel and Marston in Bitland

time limit per test 5 seconds
memory limit per test 256 megabytes
input standard input
output standard output

A couple of friends, Axel and Marston are travelling across the country of Bitland. There are n towns in Bitland, with some pairs of towns connected by one-directional roads. Each road in Bitland is either a pedestrian road or a bike road. There can be multiple roads between any pair of towns, and may even be a road from a town to itself. However, no pair of roads shares the starting and the destination towns along with their types simultaneously.

The friends are now located in the town 1 and are planning the travel route. Axel enjoys walking, while Marston prefers biking. In order to choose a route diverse and equally interesting for both friends, they have agreed upon the following procedure for choosing the road types during the travel:

  • The route starts with a pedestrian route.
  • Suppose that a beginning of the route is written in a string s of letters P (pedestrain road) and B (biking road). Then, the string  is appended to s, where  stands for the string s with each character changed to opposite (that is, all pedestrian roads changed to bike roads, and vice versa).

In the first few steps the route will look as follows: P, PB, PBBP, PBBPBPPB, PBBPBPPBBPPBPBBP, and so on.

After that the friends start travelling from the town 1 via Bitlandian roads, choosing the next road according to the next character of their route type each time. If it is impossible to choose the next road, the friends terminate their travel and fly home instead.

Help the friends to find the longest possible route that can be travelled along roads of Bitland according to the road types choosing procedure described above. If there is such a route with more than 1018 roads in it, print -1 instead.

Input

The first line contains two integers n and m (1 ≤ n ≤ 500, 0 ≤ m ≤ 2n2) — the number of towns and roads in Bitland respectively.

Next m lines describe the roads. i-th of these lines contains three integers viui and ti (1 ≤ vi, ui ≤ n, 0 ≤ ti ≤ 1), where vi and uidenote start and destination towns indices of the i-th road, and ti decribes the type of i-th road (0 for a pedestrian road, 1 for a bike road). It is guaranteed that for each pair of distinct indices ij such that 1 ≤ i, j ≤ m, either vi ≠ vj, or ui ≠ uj, or ti ≠ tj holds.

Output

If it is possible to find a route with length strictly greater than 1018, print -1. Otherwise, print the maximum length of a suitable path.

Examples
input
2 2
1 2 0
2 2 1
output
3
input
2 3
1 2 0
2 2 1
2 2 0
output
-1
Note

In the first sample we can obtain a route of length 3 by travelling along the road 1 from town 1 to town 2, and then following the road 2 twice from town 2 to itself.

In the second sample we can obtain an arbitrarily long route by travelling the road 1 first, and then choosing road 2 or 3 depending on the necessary type.

倍增 位运算 bitset

博主当然会做这种题啦,只要用心思考很快就能得出解法了。

——可是听说博主的代码是从standings榜上rank4那里抄来的,连变量名都没怎么改就贴到博客上了呢

——啊啊啊啊啊啊啊啊啊啊读书人的事,怎么能算抄呢……是学习……学习!

(好像有点熟悉)

用bitset存储状态,倍增以u为起点走2^k步可以到哪些点。

处理完状态以后,从2^61开始倒着贪心。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<bitset>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
bitset<>f[][][mxn];//类型 倍增长度 起始点=终点
bitset<>p,q;
int n,m;
int main(){
int i,j,u,v,w;
n=read();m=read();
for(i=;i<=m;i++){
u=read();v=read();w=read();
--u;--v;
f[w][][u][v]=;
}
for(int k=;k<;k++){
for(i=;i<n;i++){
for(j=;j<n;j++){
if(f[][k-][i][j])f[][k][i]|=f[][k-][j];
if(f[][k-][i][j])f[][k][i]|=f[][k-][j];
}
}
}
for(i=;i<n;i++)
if(f[][][][i]){
printf("-1\n");return ;
}
bool tp=;
long long ans=;
p[]=;
for(int k=;k>=;k--){
for(i=;i<n;i++)q[i]=;
for(j=;j<n;j++)if(p[j]) q|=f[tp][k][j];
if(q.any()){
tp^=;
ans+=(1LL<<k);
p=q;
}
}
if(ans>1e18)ans=-;
printf("%I64d\n",ans);
return ;
}

CodeForces Round #403 (Div.2) A-F的更多相关文章

  1. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  2. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  3. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  4. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  5. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  6. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  7. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

  8. Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)

    Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Mee ...

  9. Codeforces Round#403 (Div. 1)

    唉,昨天晚上迷迷糊糊地去打cf,结果fst两题,掉回蓝了... A.Andryusha and Colored Balloons 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色 ...

  10. Codeforces Round #322 (Div. 2) E F

    E. Kojiro and Furrari 题意说的是 在一条直线上 有n个加油站, 每加一单位体积的汽油 可以走1km 然后每个加油站只有一种类型的汽油,汽油的种类有3种 求从起点出发到达终点要求使 ...

随机推荐

  1. 【PHP】Maximum execution time of 30 seconds exceeded解决办法

    Maximum execution time of 30 seconds exceeded,今天把这个错误的解决方案总结一下: 简单总结一下解决办法: 报错一:内存超限,具体报错语句忘了,简单说一下解 ...

  2. .c和.h区别

    本质没有区别: .h是头文件 一般情况下下边内容放在.h文件中 宏定义 结构体,联合,枚举声明 typedef声明 外部函数声明 全局变量声明 .c是程序文件 一般情况下下边内容放在.h文件中 内含函 ...

  3. list函数及list对象的reverse方法

    list的reverse方法,是就地reverse,不返回值 如a是一个list,a.reverse()直接将a这个list给reverse了,所以如果print(a.reverse())就是None ...

  4. 笔记-python-lib-lxml

    笔记-python-lib-lxml 1.      lxml简介 lxml是一个实现解析网页文件的库,python中自带有解析库,但没有lxml方便好用. The lxml XML toolkit ...

  5. PHP.32-TP框架商城应用实例-后台8-商品相册-添加

    商品相册[是商品的其他相片] 添加相册需求: 每张图片生成三张缩略图{50*50.350*350.650*650} 1.建表p39_goods_pic{id,pic,sm_pic,mid_pic,bi ...

  6. div+css实现双飞翼布局

    本例通过div+css实现HTML金典布局双飞翼布局,该布局结构为上中下结构,上:header头:下:footer尾:中:内容,将内容分为了三个结构,左中右 下图是效果图 我们来看下代码 <!D ...

  7. centos使用--supervisor使用

    目录 1 下载程序并安装 2 编辑配置文件 3 supervisor的使用 4 配置文件详细解析 参考资料 supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变 ...

  8. 关于ADB push 出现failed to copy 'D:\file.xtxt' to '/system/temp/' : Read-only file system 的报错信息解决办法

    首先使用USB连接电脑与小机,然后安装adb相应的驱动,这是第一步,也是必须要做的. 进入doc系统后,敲入adb shell  可以进入linux命令行状态,说明adb可以使用了. 回到标题,我们现 ...

  9. Python网络编程(weekly summary1)

    网络的目的是什么?     用于信息传输.接受  能把各个点.面.体的信息链接到一起 实现资源的共享 OSI模型:     应用层:提供程序服务     表示层:数据加密.优化.压缩     会话层: ...

  10. PHP vscode+XDebug 远程断点调试服务器上的代码

    对于简单的项目或仅仅想知道某一位置的某个变量是什么值,直接使用var_dump配置exit来打印和中断就可以了,方便又快捷, 而对于大型项目的调试,或想了解某个系统的整个运行过程,xdebug可能会是 ...