比赛链接:https://codeforces.com/gym/104976
D.Operator Precedence
队友解的,想办法让第二个式子中括号内数值为1,所以就2,-1交替,最后一个选1可逆推,第一个为2*n-3
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
//const ll p=rnd()%mod;
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll query(ll l,ll r)
{
cout<<"?"<<" "<<l<<" "<<r<<endl;
cout.flush();
ll x;
cin>>x;
return x;
}
ll a[2500000];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
cout<<2*n-3<<" ";
for(ll i=2;i<=2*n-1;i++)
{
if(i%2==0)
cout<<2<<" ";
else
cout<<-1<<" ";
}
cout<<1<<endl;
}
}
G.Snake Move
模2的64次方,其实意味着你得开unsigned long long统计最后答案,
对于bfs,如果你到了某个点无非就是这个时候的距离,或者等待蛇身离开
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
//mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool vis[4000][4000];
ll vi[4000][4000];
ll dis[4000][4000];
ll a[4]={0,1,0,-1};
ll b[4]={1,0,-1,0};
ll gs=0;
ll n,m,k;
void bfs(ll x,ll y)
{
priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>>q;
q.push({0,{x,y}});
dis[x][y]=0;
while(!q.empty())
{
ll x=q.top().second.first;
ll y=q.top().second.second;
ll Dis=q.top().first;
q.pop();
ll u;
vis[x][y]=1;
for(ll i=0;i<=3;i++)
{
ll nx=x+a[i];
ll ny=y+b[i];
if(nx<1||nx>n||ny<1||ny>m||vis[nx][ny])
{
continue;
}
else
{
if(vi[nx][ny])
{
u=max(dis[x][y]+1,vi[nx][ny]+1);
}
else u=dis[x][y]+1;
dis[nx][ny]=u;
q.push({dis[nx][ny],{nx,ny}});
vis[nx][ny]=1;
}
}
}
}
int main()//附着花费
{
fio();
cin>>n>>m>>k;
ll s1=0,s2=0;
for(ll i=1;i<=k;i++)
{
ll x,y;
cin>>x>>y;
if(s1==0)
{
s1=x,s2=y;
}
if(i>=2)
{
vi[x][y]=k-i;
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)dis[i][j]=99999999999;
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
char g;
cin>>g;
if(g=='#')vis[i][j]=1;
}
}
//cout<<s1<<" "<<s2<<endl;
bfs(s1,s2);
unsigned long long ans=0;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
if(dis[i][j]==99999999999){
continue;
}
//cout<<i<<" "<<j<<" "<<dis[i][j]<<endl;
ans+=dis[i][j]*dis[i][j];
}
}
cout<<ans<<endl;
}
H. Sugar Sweet II
队友推得概率和深度有关,然后就是先把非环特判,然后有环都认为糖果为基础糖果即可
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll p1=ksm(2,mod-2);
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll query(ll l,ll r)
{
cout<<"?"<<" "<<l<<" "<<r<<endl;
cout.flush();
ll x;
cin>>x;
return x;
}
struct s
{
ll x,y,w;
}p[550000];
struct f
{
ll x,y,w;
};
vector<ll>g[555000];
bool vi[550000];
ll ans[552000];
ll in[550000];
ll op[555000];
ll cs=0;
ll ou[550000];
void bfs(ll x,ll sd,ll cd)
{
queue<f>q;
q.push({x,sd,cd});
//cout<<x<<endl;
while(!q.empty())
{
ll x=q.front().x;
ll sd=q.front().y;
ll cd=q.front().w;
for(auto j:g[x])
{
in[j]--;
if(in[j]==0)
{
q.push({j,sd+1,(cd%mod*ksm(sd+1,mod-2)%mod)%mod});
ll cg=(cd%mod*ksm(sd+1,mod-2)%mod)%mod;
ans[j]=cg*((p[j].x+p[j].w)%mod)%mod;
ans[j]+=((1-cg%mod+1000*mod)%mod*(p[j].x)%mod)%mod;
ans[j]%=mod;
}
}
q.pop();
}
}
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)cin>>p[i].x,g[i].clear();
for(ll i=1;i<=n;i++)cin>>p[i].y,vi[i]=0,in[i]=0,ou[i]=0;
for(ll i=1;i<=n;i++)cin>>p[i].w,op[i]=0;
set<ll>q;
for(ll i=1;i<=n;i++)
{
if(p[i].y==i)
{
op[i]=0;
ans[i]=p[i].x;
}
else if(p[p[i].y].x>p[i].x)
{
op[i]=1;
ans[i]=p[i].x+p[i].w;
ans[i]%=mod;
q.insert(i);
//cout<<i<<endl;
}
else if(p[p[i].y].x+p[p[i].y].w<=p[i].x)
{
op[i]=0;
ans[i]=p[i].x;
ans[i]%=mod;
q.insert(i);
}
else g[p[i].y].push_back(i),in[i]++;
}
//cout<<ans[2]<<" "<<ans[4]<<endl;
for(auto j:q)
{
bfs(j,1,op[j]);
vi[j]=1;
}
for(ll i=1;i<=n;i++)
{
if(in[i]>0)
cout<<p[i].x%mod<<" ";
else
cout<<ans[i]%mod<<" ";
}
cout<<endl;
}
}
J. Mysterious Tree
注意题目给的是树,然后二二配对问就好了
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
//const ll p=rnd()%mod;
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll query(ll l,ll r)
{
cout<<"?"<<" "<<l<<" "<<r<<endl;
cout.flush();
ll x;
cin>>x;
return x;
}
ll a[2500000];
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)a[i]=0;
if(n%2==0)
{
for(ll i=1;i<=n/2;i++)
{
a[i]=query(i,i+n/2);
}
ll ans=0;
ll wz;
for(ll i=1;i<=n/2;i++)
{
ans+=a[i];
if(a[i]==1)
wz=i;
}
if(ans==0||ans>=2)//必须为1,如果为星
{
cout<<"!"<<" "<<1<<endl;
}
else
{
ll pd;
if(wz==1)
pd=2;
else pd=1;
ll cnt=query(wz,pd);
if(cnt==1)
{
if(query(wz,pd+n/2)==1)
{
cout<<"!"<<" "<<2<<endl;
}
else cout<<"!"<<" "<<1<<endl;
}
else
{
if(query(wz+n/2,pd)==1&&query(wz+n/2,pd+n/2)==1)
{
cout<<"!"<<" "<<2<<endl;
}
else cout<<"!"<<" "<<1<<endl;
}
}
}
else
{
ll sum=0;
ll wz;
for(ll i=1;i<=n/2;i++)
{
a[i]=query(i,i+n/2);//1 3 2 4
sum+=a[i];
if(a[i]==1)
wz=i;
}
if(sum>=2)
{
cout<<"!"<<" "<<1<<endl;
}
else if(sum==1)
{
ll pd;
if(wz==1)
pd=2;
else pd=1;
if(query(wz,n)==1)
{
if(query(wz,pd)==1)
{
cout<<"!"<<" "<<2<<endl;
}
else
{
cout<<"!"<<" "<<1<<endl;
}
}
else
{
if(query(wz+n/2,n)==0)
{
cout<<"!"<<" "<<1<<endl;
}
else
{
if(query(wz+n/2,pd)==1)
{
cout<<"!"<<" "<<2<<endl;
}
else
{
cout<<"!"<<" "<<1<<endl;
}
}
}
}
else
{
if(query(1,n)==1&&query(2,n)==1&&query(3,n)==1)
{
cout<<"!"<<" "<<2<<endl;
}
else
cout<<"!"<<" "<<1<<endl;
}
}
}
}
M. V-Diagram
最大值就是V+单边或者双边
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
//const ll p=rnd()%mod;
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll a[450000];
int main()
{
//fio();
ll t;
cin>>t;
while(t--)
{
ll n;
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
ll wz=0;
for(ll i=2;i<=n-1;i++)
{
if(a[i-1]>a[i]&&a[i]<a[i+1])
{
wz=i;
break;
}
}
double ans=0;
ll cnt=0;
for(ll i=1;i<=wz;i++)
{
cnt+=a[i];
}
for(ll i=wz+1;i<=n;i++)
{
//double k=
cnt+=a[i];
ans=max(ans,(double)cnt/i);
}
cnt=0;
for(ll i=wz;i<=n;i++)
{
cnt+=a[i];
}
//cout<<wz<<endl;
for(ll i=wz-1;i>=1;i--)
{
cnt+=a[i];
ans=max(ans,(double)cnt/(n-wz+1+(wz-i)));
}
printf("%.20lf\n",ans);
}
}
标签:2024.10,return,23,ll,练习,x%,ans,include,mod
From: https://www.cnblogs.com/cjcf/p/18499736