【Codeforces Round #557 (Div. 2) [based on Forethought Future Cup - Final Round] A B C D E 】

71 篇文章 0 订阅

CF557
A . Zoning Restrictions Again
题意 给你n个建筑 每个建筑只能建 0 - h 的高度 有m个限制 使得 l 到 r 最多建 m[i]高度
那么我们只要暴力取最小值
O(n)统计答案即可

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
int maxx[55];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,h,m,a,b,c;
    ll ans = 0;
    scanf("%d%d%d",&n,&h,&m);
    for(int i = 1;i<=n;++i) maxx[i] = h;
    for(int i = 1;i<=m;++i)
    {
        scanf("%d%d%d",&a,&b,&c);
        for(int j = a;j<=b;++j)
            maxx[j] = min(maxx[j],c);
    }
    for(int i = 1;i<=n;++i)
        ans+=1ll*maxx[i]*maxx[i];
    printf("%lld\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

B . Double Matrix
题意 给你两个矩阵 你可以交换两个矩阵中下标相同的元素 问你能不能使得每个元素都大于他右边和他下面的元素
一开始没想到做法 后来其实如果你合法 你就把所有大的元素放在上面矩阵 小的元素放在下面矩阵
然后再分别check一遍即可

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
int mp[55][55],mp_[55][55],mp__[55][55],mp___[55][55];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m;
    bool flag = true;
    scanf("%d%d",&n,&m);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=m;++j)
            scanf("%d",&mp[i][j]);
    for(int i = 1;i<=n;++i) mp__[i][m+1]=mp___[i][m+1] = inf;
    for(int i = 1;i<=m;++i) mp__[n+1][i] =mp___[n+1][i]= inf;
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=m;++j)
            scanf("%d",&mp_[i][j]);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=m;++j)
            mp__[i][j] = max(mp[i][j],mp_[i][j]),mp___[i][j] = min(mp[i][j],mp_[i][j]);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=m;++j)
        {
            if(mp__[i][j]>=mp__[i+1][j]||mp__[i][j]>=mp__[i][j+1]||mp___[i][j]>=mp___[i+1][j]||mp___[i][j]>=mp___[i][j+1])
            {
                flag = false;
                break;
            }
        }
    if(flag) printf("Possible\n");
    else printf("Impossible\n");
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

C. Hide and Seek
题意 就是问你k个位置 你一开始在一个位置 任何询问前或者询问后你可以去另一个位置
问你答案数使得不会被询问到
那么我们知道所有序列就是 3n-2( 减去0到1 和 n+1到n的 为什么是3 因为相邻和本身
那么我们发现 如果一个数前面的数在前面出现过 那么序列 arr[i]-1,arr[i]就非法
如果一个数后面的数在前面出现过 那么序列 arr[i]+1,arr[i]就非法
arr[i] arr[i] 肯定是非法的
所以你就用桶装所有位置 然后O(3
n) check即可

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 100025;
int arr[MAX_N],tong[MAX_N];
map<pll,int> mp;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,k,ans;
    scanf("%d%d",&n,&k);
    ans = n*3 - 2;
    for(int i = 1;i<=k;++i)
    {
        scanf("%d",&arr[i]);
        if(tong[arr[i]]==0)
        {
            ans--;
            tong[arr[i]]++;
        }
        if(tong[arr[i]-1]&&mp.find(pll(arr[i]-1,arr[i]))==mp.end()) ans--,mp[make_pair(arr[i]-1,arr[i])] = 1;
        if(tong[arr[i]+1]&&mp.find(pll(arr[i]+1,arr[i]))==mp.end()) ans--,mp[make_pair(arr[i]+1,arr[i])] = 1;
    }
    printf("%d\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

D. Chladni Figure
题意 就是给你一个圆 还有点
问你能不能旋转 k 使得和原图重合
我们发现 k 只可能是 n 的约数
所以我们把所有边放进一个set
然后暴力枚举所有边是否合法即可

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
vector<int> vt[1000025];
vector<pll> VT,vt_;
set<pll> st;
const int MAX_N = 1000025;
void init()
{
    for(int i = 1; i<=1000000; i++)
    {
        for(int j = i; j<=1000000; j+=i)
        {
            vt[j].push_back(i);
        }
    }
}
bool cmp(pair<int,int> a,pair<int,int> b){
	if(a.first != b.first) return a.first < b.first;
	return a.second < b.second;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int ans = 0,a,b;
    init();
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=k;++i)
    {
        scanf("%d%d",&a,&b);
        if(a>b) swap(a,b);
        st.insert(make_pair(a,b));
        vt_.push_back(pll(a,b));
    }
    int sz_ = vt[n].size(),sz=  vt_.size();
    bool flag = false;
    for(int i = 0;i<sz_;++i)
    {
        int tmp = vt[n][i];
        if(tmp==n) continue;
        bool flag_ = true;
        for(int j = 0;j<sz;++j)
        {
            int now = tmp + vt_[j].first,now_ = tmp + vt_[j].second;
            if(now>n) now-=n;
            if(now_>n) now_-=n;
            if(now>now_) swap(now,now_);
            if(st.find(pll(now,now_))==st.end()) flag_ = false;
        }
        if(flag_)
        {
            flag = true;
            break;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

E. Thanos Nim
博弈论好题
给你 n 个石头 玩家每次必须选 n/2(n是偶数 个石头删除正数个石头 可以删不同个
问你谁不能删 谁就输了
这题的策略是最小值的出现次数 如果小于等于n/2 那么我们肯定不修改最小值
把问题转换成必败态
但是如果大于 那么就一定是必败态

/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)
-
    #undef mid
}*/
int arr[55],num[55];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    ll d,tmp = 0;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
    {
        scanf("%d",&arr[i]);
        num[arr[i]]++;
    }
    sort(arr+1,arr+1+n);
    if(num[arr[1]]<=n/2) printf("Alice\n");
    else printf("Bob\n");
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值