2022杭电暑期第七场个人题解

1010

签到题,模拟一下

#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int mod=998244353;
void solve()
{
    int n,m;
    cin>>n;
    vector<int>cnt(7);
    int tot=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(!cnt[x])tot++;
        cnt[x]++;
    }
    for(int i=1;i<=6;i++)cnt[i]=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(!cnt[x])tot++;
        cnt[x]++;
    }
    if(tot==2*n){
        cout<<"Just a game of chance.\n";
    }else cout<<"Win!\n";
}
signed main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)solve();
}

1012

bitset确实好用,用bitset节省空间和时间,进行模拟暴力

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
const int N = 200005;
struct node{
	int l,r;
}qj[N];

bool cmp(node x,node y) {
	if(x.l != y.l) return x.l<y.l;
	else return x.r > y.r; 
} 
bitset<200001> ma[20004];
void solve() {
	int n,m;
	cin>>n>>m;
	int maxx=0; 
	for(int i=1;i<=n;i++) {
		cin>>qj[i].l>>qj[i].r;
		maxx=max(qj[i].r,maxx);
	}
	ll ans = 20000*20000;
	if(n<=m) {
		cout<<maxx<<endl;
		return ;
	}
	int rmax = 0,fmax=0;
	sort(qj+1,qj+1+n,cmp);
	int minn=1<<29,mink=0;
	for(int i=1;i<=n;i++) {
		bool z=false;
		for(int j=1;j<=m;j++) {
			bool ok = 1;
			for(int k=qj[i].l;k<=qj[i].r;k++) {
				int temp = qj[i].l ; 
				if(ma[m][k] == 1 ) {
					ok = false;
					temp = k;
				}
				if(temp<minn) {
					minn = temp;
					mink = j;
				}
				//minn = min (temp,minn);
			}
			if(ok) {
				for(int k=qj[i].l;k<=qj[i].r;k++) {
					ma[m][k] = 1;
					rmax = max(rmax,k);
				}
				z=1;
			}
		}
		if(!z) {
			for(int k=qj[i].l;k<=qj[i].r;k++) {
				ma[mink][k] = 1;
				fmax = max(k,fmax);
			}
		}
	}
	ans=max(rmax,fmax);
	cout<<ans<<endl;
}
int main() {
	int t;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;	
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值