爆炸的联赛模拟 8.24~8.25
爆炸的联赛模拟 8.24_8.25
首先吐槽又都用原题。所以没有密码
T1
考试手抽了不知道要去重就GG了,傻逼题,给出两种代码(map,sort),不多说。
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<map>
#define Fname "loverfinding"
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
typedef long long ll;
il int gi(){
rg int x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
map<pair<int,int>,char>m;
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
int n=gi(),x0=gi(),y0=gi(),xt=gi(),yt=gi();
if(x0==xt&&y0==yt){puts("1");return 0;}
m[make_pair(x0,y0)]=0;
rep(i,1,n){
x0+=gi(),y0+=gi();
m[make_pair(x0,y0)]=0;
if(x0==xt&&y0==yt){printf("%d\n",m.size());return 0;}
}puts("SingleDog");
return 0;
}
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#define Fname "loverfinding"
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
typedef long long ll;
il int gi(){
rg int x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
pair<int,int>s[1000001];
#define mp make_pair
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
int n=gi(),tot=0,x0=gi(),y0=gi(),xt=gi(),yt=gi();
s[0]=mp(x0,y0);
if(x0==xt&&y0==yt){puts("1");return 0;}
while(n--){
x0+=gi(),y0+=gi();
s[++tot]=mp(x0,y0);
if(x0==xt&&y0==yt)break;
}
sort(s+0,s+tot+1);
int prt=1;
rep(i,1,tot)if(s[i]!=s[i-1])++prt;
printf("%d",prt);
return 0;
}
PS.map会炸飞,我用sort还上榜了。。。
T2
COGS上交题记录成堆了(没kuai数据)
。。。。。
简单说一下吧。。。
首先设\(f[k][i][j]\)为经过费用前k的点、i~j的最短路
转移就是floyd的松弛操作
\[f[k][i][j]=f[k-1][i][v[k]]+f[k-1][v[k]][j]
\]
f[0]即为原图邻接矩阵。
求出\(f[k][i][j]\)后,其实已经可以AC了。。。
对于询问先求出k,枚举j,i=s,爆算
加两个二分,即首先对于每个\(f[k][i]\)排序,就可以二分k,j求解
还有在改题时出现读入优化删了就T->W的灵异事件
//无二分,可能被卡,没读入优化2.278s
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<cstring>
#define Fname "snackstore"
using namespace std;
#define rep(a,b,c) for(rg ll a=b;a<=c;a++)
#define drep(a,b,c) for(rg ll a=b;a>=c;a--)
#define erep(a,b) for(rg ll a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
#define t (dis[i])
typedef long long ll;
il ll gi(){
/*
rg ll x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
*/
ll ret;
#ifdef xzz
scanf("%I64d",&ret);
#else
scanf("%lld",&ret);
#endif
return ret;
}
const int maxn=101,maxm=10010;
ll v[maxn];
ll f[maxn][maxn][maxn],n,m,q;
struct haha{ll v,id;}s[maxn];
bool operator <(haha a,haha b){return a.v<b.v;}
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
n=gi(),m=gi(),q=gi();
rep(i,1,n)s[i].v=gi(),s[i].id=i;
sort(s+1,s+n+1);
rep(i,1,n)v[i]=s[i].id;
ll a,b,l;
rep(i,1,n)rep(j,i+1,n)f[0][i][j]=f[0][j][i]=1e9+1;
rep(i,1,m)a=gi(),b=gi(),l=gi(),f[0][a][b]=f[0][b][a]=min(f[0][a][b],l);
rep(k,1,n)rep(i,1,n)rep(j,1,n)f[k][i][j]=min(f[k-1][i][j],f[k-1][i][v[k]]+f[k-1][v[k]][j]);
rep(k,0,n)rep(i,1,n)sort(f[k][i]+1,f[k][i]+1+n);
rep(i,1,q){
ll ss=gi(),c=gi(),d=gi(),ans=0;
ll k=0;
while(k<n&&s[k+1].v<=c)k++;
rep(j,1,n)if(f[k][ss][j]<=d)++ans;else break;
#ifdef xzz
printf("%I64d\n",ans-1);
#else
printf("%lld\n",ans-1);
#endif
}
return 0;
}
//加了二分,没读入优化2.114s,加了就1.684s
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<cstring>
#define Fname "snackstore"
using namespace std;
#define rep(a,b,c) for(rg ll a=b;a<=c;a++)
#define drep(a,b,c) for(rg ll a=b;a>=c;a--)
#define erep(a,b) for(rg ll a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
#define t (dis[i])
typedef long long ll;
il ll gi(){
rg ll x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
const int maxn=101,maxm=10010;
ll v[maxn];
ll f[maxn][maxn][maxn],n,m,q;
struct haha{ll v,id;}s[maxn];
bool operator <(haha a,haha b){return a.v<b.v;}
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
n=gi(),m=gi(),q=gi();
rep(i,1,n)s[i].v=gi(),s[i].id=i;
sort(s+1,s+n+1);
rep(i,1,n)v[i]=s[i].id;
ll a,b,l;
rep(i,1,n)rep(j,i+1,n)f[0][i][j]=f[0][j][i]=1e9+1;
rep(i,1,m)a=gi(),b=gi(),l=gi(),f[0][a][b]=f[0][b][a]=min(f[0][a][b],l);
rep(k,1,n)rep(i,1,n)rep(j,1,n)f[k][i][j]=min(f[k-1][i][j],f[k-1][i][v[k]]+f[k-1][v[k]][j]);
rep(k,0,n)rep(i,1,n)sort(f[k][i]+1,f[k][i]+1+n);
rep(i,1,q){
ll ss=gi(),c=gi(),d=gi();
ll k,l=0,r=n;
while(l<r)
if(s[(l+r>>1)+1].v<=c)l=(l+r>>1)+1;
else r=l+r>>1;
k=l;
l=0,r=n;
while(l<r)
if(f[k][ss][(l+r>>1)+1]<=d)l=(l+r>>1)+1;
else r=l+r>>1;
#ifdef xzz
printf("%I64d\n",l-1);
#else
printf("%lld\n",l-1);
#endif
}
return 0;
}
T3
这。。。还改什么改
T4
一道水题。记忆搜乱搞。
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#define Fname "three_squirrels"
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
typedef long long ll;
il int gi(){
rg int x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
int a[100001][10],k[100001];
int g[100001];
il int f(int s){
if(g[s])return g[s];
rep(i,0,k[s]-1)g[s]=(g[s]+f(a[s][i]))%1000000007;
return g[s];
}
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
int n=gi();
rep(i,1,n){
k[i]=gi();
rep(j,0,k[i]-1)a[i][j]=gi();
}
g[0]=1;
printf("%d\n",f(n));
return 0;
}
吐槽一下文件名“三只松鼠”(给了你多少钱?我每日坚果翻一倍!)
T5
好题哈。kmp求一遍nxt数组然后\(add(a,nxt[a],(a-nxt[a])^2)\),跑树上最长链。
ps.数据是有多水,我nxt数组求错还有70'。。。
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<cstring>
#define Fname "savemzx"
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
typedef long long ll;
il int gi(){
rg int x=0,f=1;rg char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return x*f;
}
const int maxn=1000005;
char str[maxn];
int Nxt[maxn];
int id,fir[maxn],nxt[maxn],dis[maxn];
ll w[maxn],Fir[maxn],Sec[maxn];
il vd add(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b,w[id]=((ll)a-b)*(a-b);}
ll ans=0;
il vd Updata(ll&a,ll&b,ll c){
if(c>a)b=a,a=c;
else if(c>b)b=c;
}
il vd L(int now){
Fir[now]=Sec[now]=0;
erep(i,now){
L(dis[i]);
Updata(Fir[now],Sec[now],Fir[dis[i]]+w[i]);
}
ans=max(ans,Fir[now]+Sec[now]);
}
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
scanf("%s",str+1);
int len=strlen(str+1);
Nxt[0]=0;
Nxt[1]=0;
rep(i,2,len){
int k=Nxt[i-1];
while(k&&str[k+1]!=str[i])k=Nxt[k];
if(str[k+1]==str[i])++k;
Nxt[i]=k;
}
rep(i,1,len)add(Nxt[i],i);
L(0);
printf("%lld\n",ans);
return 0;
}
T6
没开始改。这里先留个坑,以后再跳。。。
博主是蒟蒻,有问题请指出,谢谢!
本博客中博文均为原创,未经博主允许请勿随意转载,谢谢。
本博客中博文均为原创,未经博主允许请勿随意转载,谢谢。