AtCoder Beginner Contest 167

A - Registration

签到

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;

int main()
{
	string a,b;
	cin>>a>>b;
	int flag=1;
	for(int i=0;i<a.size();i++){
		if(a[i]!=b[i]) flag=0;
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}

B - Easy Linear Programming

签到

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=0;
	if(a<=k) ans+=a,k-=a;
	else if(a>k) ans=k,k=0;
	if(k>0) k-=b;
	if(k>0) ans-=k;
	cout<<ans<<endl;
	return 0;
}

C - Skill Up

每本书选或者不选,很明显地,直接爆搜一波取最小花费就可以了;

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;

struct node{
	int c;
	int le[15];
}a[15];
int n,m,k;
int ans=INF;
int dis[15];

void dfs(int x,int cost)
{
	int flag=1;
	for(int i=1;i<=m;i++) if(dis[i]<k) flag=0;
	if(flag){
		ans = min(ans,cost); return ;
	}
	if(x>n) return ;
	for(int i=1;i<=m;i++) dis[i] += a[x].le[i];
	dfs(x+1,cost+a[x].c);
	for(int i=1;i<=m;i++) dis[i] -= a[x].le[i];
	
	dfs(x+1,cost);
}

int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i].c;
		for(int j=1;j<=m;j++) cin>>a[i].le[j];
	}
	dfs(1,0);
	if(ans==INF) cout<<"-1\n";
	else cout<<ans<<endl;
	return 0;
}

D - Teleporter

很明显地,得找循环节,然后取模循环节大小输出位置就行了;

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;

int a[N];
int dis[N*2],cnt;
bool st[N];
int main()
{
	LL n,k;
	cin>>n>>k;
	int tt;
	for(int i=1;i<=n;i++) cin>>tt,a[i]=tt;
	int x=1,t=0,next;
	while(!st[x]&&t<k){
		st[x] = 1;
		dis[++cnt] = x;
		x = a[x];
		t++;
	}
//	for(int i=1;i<=cnt;i++) cout<<dis[i]<<" ";
//	cout<<endl;
	if(t==k) cout<<x<<endl;
	else {
		int pos=1;
		for(int i=1;i<=cnt;i++){
			if(dis[i]==x) pos = i;
		}
		//cout<<pos<<endl; 
		int xun = cnt-pos+1;
		k=k-pos+1;
		k%=xun;
		cout<<dis[pos+k]<<endl;
	}
	return 0;
}

E - Colorful Blocks *

排列组合

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 998244353;

LL quick(LL a,LL b){
	LL ans=1;
	while(b){
		if(b&1) ans = ans*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return ans;
}

int main()
{
	LL n,m,k,t=1,ans=0;
    cin>>n>>m>>k;
    for(LL i=0;i<=k;i++){
        ans = (ans+(t*m%mod) * quick(m-1,n-i-1))%mod;
        t = t*(n-i-1) % mod * quick(i+1,mod-2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

F - Bracket Sequencing

待补

唉,手速不够 (太菜),后两题题都没来得及搞 QAQ(虽然不一定能A ,不过前边都一发A还挺爽的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值