CF1999 div4 VP 题解

A

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

void work()
{
    int n;
    cin>>n;
    cout<<n%10+n/10<<'\n';
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

B

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

void work()
{
    vi a(2),b(2);
    cin>>a[0]>>a[1]>>b[0]>>b[1];
    int ans=0;
    rep(i,0,1)
        rep(j,0,1)
        {
            int sum=0;
            if(a[i]>b[j]) sum++;
            else if(a[i]<b[j]) sum--;
            if(a[1-i]>b[1-j]) sum++;
            else if(a[1-i]<b[1-j]) sum--;
            if(sum>0) ans++;
        }
    cout<<ans<<'\n';
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

C

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

void work()
{
    int n,m,s;
    cin>>n>>s>>m;
    vector<pii> tim(n);
    rep(i,0,n-1)
        cin>>tim[i].first>>tim[i].second;
    int mx=tim[0].first;
    rep(i,1,n-1)
    {
        mx=max(mx,tim[i].first-tim[i-1].second);
    }
    mx=max(mx,m-tim[n-1].second);
    cout<<(mx>=s?"YES":"NO")<<'\n';
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

D

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

void work()
{
    string s,t;
    cin>>s>>t;
    int p=0;
    rep(i,0,sz(s)-1)
    {
        if(s[i]=='?') s[i]=t[p],p++;
        else if(s[i]==t[p]) p++;
        if(p==sz(t))
        {
            cout<<"Yes\n";
            trav(j,s)
                cout<<(j=='?'?'a':j);
            cout<<'\n';
            return;
        }
    }
    cout<<"No\n";
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

E

题目大意:

一开始黑板上有 [ l , r ] [l,r] [l,r]中的所有数

每次可以从中选择两个数 x , y x,y x,y擦去,并将这两个数替换成 3 x , ⌊ y 3 ⌋ 3x,\lfloor \frac{y}{3} \rfloor 3x,3y,问多少次操作后能够将所有数变成0

思路:很容易想到先弄一个0出来,然后剩下的所有数的代价就是 l o g 3 x log_3x log3x

因为整数中,多个不同 x x x的贡献对于 l o g 3 x log_3 x log3x是一样的,所以用整数分块的写法就可以了

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

void work()
{
    int l,r;
    cin>>l>>r;
    int ans=0;
    int pos;
    for(int x=1,val=1;x<=r;x*=3,val++)
    {
        if(l>=x) pos=val;
        ans+=val*max(0,min(3*x-1,r)-max(l,x)+1);
    }
    cout<<ans+pos<<'\n';
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

F

题目大意:

给定一个只有0和1的序列,问所有长度为 k k k k k k为奇数)的子序列的中位数的总和

思路:

就这题没写出来,看到子序列,直接选就完事了,唐完了

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e5;
ll fac[maxn+5],infac[maxn+5];

ll qpow(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        b>>=1;a=(a*a)%mod;
    }
    return res%mod;
}
ll C(int n,int m)
{
    if(n<m) return 0;
    return (fac[n]*infac[m]%mod*infac[n-m])%mod;
}

void work()
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    rep(i,1,n)
    {
        int x;cin>>x;
        cnt+=x;
    }
    ll ans=0;
    rep(i,(k+1)/2,k)
        ans=(ans+C(cnt,i)*C(n-cnt,k-i)%mod)%mod;
    cout<<ans<<'\n';
}
int main()
{
    infac[0]=fac[0]=1;
    rep(i,1,maxn)
        fac[i]=(fac[i-1]*i)%mod;
    infac[maxn]=qpow(fac[maxn],mod-2);
    for(int i=maxn-1;i>=1;i--)
    {
        infac[i]=(infac[i+1]*(i+1))%mod;
    }
    //cout<<C(2,2)<<'\n';
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

G

交互题

有一把中间少标了一个刻度 x x x的尺子

就是说,当测量一个实际长度为 y y y的物体时

y < x y<x y<x时,得到 y y y

y ≥ x y \ge x yx时,得到 y + 1 y+1 y+1

每次可以询问 a , b a,b a,b,返回用这尺子测量得到的一个实际边长为 a , b a,b a,b的矩形的面积

至多 7 7 7次询问,得到 x x x

1 ≤ a , b ≤ 1000 1 \le a,b \le 1000 1a,b1000, 2 ≤ x ≤ 999 2 \le x \le 999 2x999

至多7次,我们知道 3 7 3^7 37大于 1000 1000 1000

想到把 x x x的可行区间分为3等份这个题就出来了

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define trav(a,x) for(auto&a : x)
#define all(x) x.begin(),x.end()
#define sz(x) (int) x.size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

int ask(int x,int y)
{
    cout<<"? "<<x<<' '<<y<<endl;
    int res;
    cin>>res;return res;
}

void work()
{
    int l=1,r=999;
    while(r-l>1)
    {
        int x1=l+(r-l)/3;
        int x2=l+(r-l)*2/3;
        int res=ask(x1,x2);
        if(res==x1*x2) l=x2;
        else if(res==x1*(x2+1)) l=x1,r=x2;
        else if(res==(x1+1)*(x2+1)) r=x1;
    }
    cout<<"! "<<r<<endl;
}
int main()
{
	cin.tie(0);
	cin.sync_with_stdio(0);
	int t=1;
	cin>>t;
	while(t--)
		work();
	return 0;
}

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值