【队伍训练2】 AtCoder Beginner Contest 165

时间:2022-07-24
本文章向大家介绍【队伍训练2】 AtCoder Beginner Contest 165,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

A 水题:

#include<bits/stdc++.h>

using namespace std;

int main(){
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    for(int i=1;;i++){
    	if(i*k > b) {
    		cout<<"NG"<<endl;
    		break;
		}
		if(i*k>=a && i*k<=b){
			cout<<"OK"<<endl;
			break;
		}
	}
	return 0;
} 

B 水题:但是会卡精度!!!

#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

int main(){
    ull x;
    cin>>x;
    ull sum = 100;
    ull tot = 0;
    while(sum<x){
    	ull res = sum /100;
    	//cout<<res<<"0---";
    	sum += res;
    	tot++;
	}
	cout<<tot;
	return 0;
} 

C dfs

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int inf = 0x3f3f3f3f;

struct node{
	int a,b,c,d;
}t[60]; 

int n,m,q,ans,s[20];

void dfs(int nw,int st){
	if(nw > n){
		int res = 0;
		for(int i = 1;i <= q;++i){
			if(s[t[i].b] - s[t[i].a] == t[i].c)
				res += t[i].d;
		}
		ans = max(ans,res);
		return ;
	}
	for(int i = st;i <= m;++i){
		s[nw] = i;
		dfs(nw+1,i);
	}
	return ;
}
int main(){
	cin >> n >> m >> q;
	for(int i = 1;i <= q;i++){
		scanf("%d %d %d %d",&t[i].a,&t[i].b,&t[i].c,&t[i].d);
	}
	ans = -inf;
	
	dfs(1,1);
	
	cout<<ans<<endl;
    return 0;
}

D 数学思维题

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;



int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll flag=-inf;

	if(n < b){
		cout<<(a*n)/b<<endl;
		return 0;
	} 
	else{
		flag = max(a*(b-1)/b,flag);
		flag = max(flag,(a*n)/b-a*(n/b));
	}
	cout<<flag<<endl;
	return 0;
}