2020牛客多校第十场

  • A Permutation
    构造
    题意:
    有一个素数p,让你构造一个长度为p-1的序列,里面的数为1~p-1,要满足xi+1 == xi*2(mod p)或者xi+1 == xi*3(mod p)
    思路:
    一直*2%mod,如果之前有一样的就*3%mod,还是不行就退出。
#include <bits/stdc++.h>
using namespace std;
const int maxn=3*(int)1e6+100;
int tc,p,vis[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>tc;
    while(tc--){
        cin>>p;
        for(int i=0; i<=p; ++i) vis[i]=0;
        vector<int> ans;
        int now=1; vis[0]=1;
        while(!vis[now]){
            vis[now]=1;
            ans.emplace_back(now);
            int temp=now*2%p;
            if(!vis[temp]) now=temp;
            else now=now*3%p;
        }
        if(int(ans.size())!=p-1) cout<<-1<<'\n';
        else{
            for(int x:ans){
                cout<<x<<' ';
            }cout<<'\n';
        }
    }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

  • B Game
    二分
    题意:
    有一个类似俄罗斯方块的图形,你现在知道每一列的高度,只能把方块向右移,并且you choose one block which has no block at its right。问你移动后能得到的最低高度是多少。
    思路:
    二分,然后从右向左推看是否可行即可。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=(ll)1e5+100;
ll tc,n,a[maxn];
bool chk(ll x){
    ll sum=0;
    for(int i=n; i>=1; --i){
        if(a[i]>=x) sum+=a[i]-x;
        else{
            sum+=a[i]-x;
            if(sum<0) sum=0; //注意一下
            //,左边高出来的部分不能给右边低的部分,因为方块只能向左移动
        }
    }
    if(sum>0) return false;
    return true;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>tc;
    while(tc--){
        cin>>n;
        for(int i=1; i<=n; ++i) cin>>a[i];
        ll l=1, r=(ll)1e9, ans=-1;
        while(l<=r){
            ll mid=(l+r)/2;
            if(chk(mid)){
                ans=mid;
                r=mid-1;
            } else{
                l=mid+1;
            }
        }
        cout<<ans<<'\n';
    }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值