C h a l l e n g e s Challenges Challenges
洛谷随机跳三道 蓝 \color{blue}蓝 蓝题完成
w
y
c
wyc
wyc巨佬题解链接:https://blog.youkuaiyun.com/Mr_wuyongcong/article/details/94711038
z
y
c
zyc
zyc巨佬题解链接:https://blog.youkuaiyun.com/SSL_ZYC/article/details/94740611
T
h
e
p
r
o
b
l
e
m
o
f
z
y
c
′
s
The\ problem\ of\ zyc's
The problem of zyc′s
难度排序:T1>T2>T3
T
h
e
p
r
o
b
l
e
m
o
f
w
y
c
′
s
The\ problem\ of\ wyc's
The problem of wyc′s
难度排序:T1>T3>T2
T
h
e
p
r
o
b
l
e
m
o
f
m
i
n
e
The\ problem\ of\ mine
The problem of mine
难度排序:T1>T3>T2
S o l u t i o n Solution Solution
T1
名称:P2738 [USACO4.1]篱笆回路Fence Loops
算法: 边转点或者并查集建图,
f
l
o
y
d
floyd
floyd或
D
i
j
Dij
Dij求解最小环
评价:建图非常恶心,补充了求最小环的知识点,第一种建图虽然稍微简单,不过要用到容斥思想
T2
名称:P2237[USACO14FEB]自动完成Auto-complete
算法:排序+暴力求解或者二分,作者用指针预处理过掉
评价:水题
T3
名称:P2622 关灯问题II
算法:
b
f
s
bfs
bfs宽搜+二进制状态压缩
评价:比较水,转移过程较恶心,其它的都很简单
R e s u l t Result Result
蒟蒻
x
x
y
xxy
xxy评测结果&完成时间:
最后时间:2019-07-05 8:02:35
巨佬
w
y
c
wyc
wyc评测结果&完成时间:
最后时间:2019-07-05 07:39:11
巨佬
z
y
c
zyc
zyc评测结果&完成时间:
最后时间:2019-07-05 16:37:36
A l l i n a l l All\ in\ all All in all
刚开始因为我后两题都是水题,所以一下子进度很快, w y c wyc wyc大爷则自创神仙算法跑了第一。。。
第二天 w y c wyc wyc大爷切题若割草,秒切两题完虐本菜鸡
自主思考方面,因为我的题较水,T2,T3自己写出来,T1想半天做不出来,看完题解后过掉
w
y
c
wyc
wyc大爷冥思苦想,看完题解后题解很垃圾,于是自创算法,吊打本菜鸡。
w y c wyc wyc大爷完虐我呀QwQ
z y c zyc zyc大爷切题如割草,瞬间秒切差分题
第二天一来,连切两题,太强了%%%
z y c zyc zyc大爷完虐我啊QwQ
C o d e s Codes Codes
T 1 T1 T1
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;int tot,n,s,t,ls[101],n1s,n2s,jh[9],g[101][101],f[101][101],ans=0x3f3f3f3f;
bool v[101][101],pd[101][101][101];
inline int read()
{
int f=0,d=1;char c;
while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
return d*f;
}
signed main()
{
n=read();
for(register int i=1;i<=n;i++)
{
s=read();ls[s]=read();n1s=read();n2s=read();
jh[0]=s;
for(register int j=1;j<=n1s;j++)
{
t=read();
v[s][t]=v[t][s]=true;
jh[j]=t;
for(register int k=1;k<j;k++)
for(register int l=0;l<k;l++)
pd[jh[j]][jh[k]][jh[l]]=pd[jh[j]][jh[l]][jh[k]]=
pd[jh[k]][jh[j]][jh[l]]=pd[jh[k]][jh[l]][jh[j]]=
pd[jh[l]][jh[j]][jh[k]]=pd[jh[l]][jh[k]][jh[j]]=true;//判三边是否交于一点
}
for(register int j=1;j<=n2s;j++)
{
t=read();
v[s][t]=v[t][s]=true;
jh[j]=t;
for(register int k=1;k<j;k++)
for(register int l=0;l<k;l++)
pd[jh[j]][jh[k]][jh[l]]=pd[jh[j]][jh[l]][jh[k]]=
pd[jh[k]][jh[j]][jh[l]]=pd[jh[k]][jh[l]][jh[j]]=
pd[jh[l]][jh[j]][jh[k]]=pd[jh[l]][jh[k]][jh[j]]=true;
}
}
memset(f,0x3f,sizeof(f));
for(register int i=1;i<=n;i++)
for(register int j=1;j<=n;j++)
if(v[i][j])
f[i][j]=g[i][j]=ls[i]+ls[j];
for(register int k=1;k<=n;k++)
{
for(register int i=1;i<k;i++)
{
if(v[i][k])
for(register int j=i+1;j<k;j++)
if(v[k][j]&&!pd[i][j][k])//不能交于一点且存在
ans=min(ans,f[i][j]+g[i][k]+g[k][j]-ls[i]-ls[j]-ls[k]);//容斥
}
for(register int i=1;i<=n;i++)
for(register int j=1;j<=n;j++)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]-ls[k]);
}
printf("%d",ans);
}
T2
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int to[26],W,q,k,i;
string h;
bool ok;
struct node
{
string s;
int id;
}S[30001];
inline bool cmp(node x,node y){return x.s<y.s;}//排个序
inline bool check(string a,string b)//判个断
{
for(register int i=0;i<b.size();i++) if(a[i]!=b[i]) return false;
return true;
}
signed main()
{
freopen("1.txt","r",stdin);
cin>>W>>q;
for(register int i=1;i<=W;i++)
{
S[i].id=i;
cin>>S[i].s;
}
sort(S+1,S+1+W,cmp);
i=1;
for(register char j='a';j<='z';j++)
{
if(S[i].s[0]==j)
{
to[j-96]=i;
while(S[i].s[0]==j) i++;//O(n)预处理出指针
}
}
while(q--)
{
cin>>k>>h;
i=to[h[0]-96];
if(!i) {puts("-1");continue;}
ok=false;
while(S[i].s[0]==h[0])//跳过去找
{
if(check(S[i].s,h)) k--;
if(!k) {cout<<S[i].id<<endl;ok=true;break;}
i++;
}
if(!ok)puts("-1");
}
}
T3
#include<cstdio>
#include<queue>
using namespace std;int n,m,d[101][11];
bool visit[1024];
struct node{bool a[11];int bs,zt;}x;
queue<node>q;
inline bool pd(bool x,int y)//判断函数
{
if(y==1) return x&0;
if(y==-1) return x|1;
if(y==0) return x;
}
signed main()
{
scanf("%d%d\n",&n,&m);
for(register int i=1;i<=m;i++)
for(register int j=1;j<=n;j++)
scanf("%d",&d[i][j]);
for(register int i=0;i<=n;i++) x.a[i]=1;
x.bs=0;x.zt=(1<<n)-1;
q.push(x);
visit[x.zt]=true;
while(q.size())
{
x=q.front();q.pop();
for(register int i=1;i<=m;i++)
{
node y;y.bs=x.bs+1;y.zt=0;
for(register int j=1;j<=n;j++)
y.a[j]=pd(x.a[j],d[i][j]),y.zt=(y.zt<<1)+y.a[j];//暴力bfs
if(visit[y.zt]) continue;
visit[y.zt]=true;
if(!y.zt) return printf("%d",y.bs)&0;
q.push(y);
}
}
puts("-1");
}