Codeforces Global Round 8 - 坑較多

B. Codeforces Subsequences

題目鏈接:https://codeforces.ml/contest/1368/problem/B
題目描述:

find any shortest string that contains at least k codeforces subsequences。找到最短的串包含至少k個(記住不是k個,而是>=k,好多人好像看錯了,哈哈!)。

分析:

儘可能找平均下來的串。

代碼:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//快速冪
ll fast_pow(ll x,ll n){
	ll res=1;
	while(n){
		if(n&1)res=res*x;
		x=x*x;
		n>>=1;
	}
	return res;
}
//判斷平均下來最多的位置需要多少個,記做p
ll panduan(ll k){
	for(ll i = 1;i <= 50;++i){
		if(fast_pow(i,10)>=k)
			return i;
	}
}
//看看有多少個位置需要最多的這個數p
ll solve(ll k, ll p){
	//看需要多少個p 
	ll sum = 1;
	for(ll i = 0; i <= 10; ++i){
		sum=1;
		sum*=fast_pow(p,i);
		sum*=fast_pow(p-1,10-i);	
		if(sum>=k)return i;
	}
}
int main()
{
	ll k;
	cin >> k;
	ll p=panduan(k);
	ll sum=solve(k,p);
	string s="codeforces";
	string ans="";
	for(int i = 0; i < sum; ++i){
		for(int j = 1; j <= p; ++j){
			ans+=s[i];
		}
	}
	for(int i = sum; i < 10; ++i){
		for(int j = 1; j <= p-1; ++j){
			ans+=s[i];
		}
	}
	cout << ans;
	return 0;
} 

C. Even Picture

題目鏈接:https://codeforces.ml/contest/1368/problem/C
題目描述:

構造一個連通圖,圖中有k個灰格4個面都是灰格,剩下(k-n)個灰格周圍2個面是灰格。記住不需要找最小k,題目中最後來一句there exists an answer satisfying all requirements with a small enough k。你就不能說能找到k不就行了,還足夠小!!太慘了!!!找最小k搞得很難受,直接構造就輕鬆多了。。。。。參考大佬博客:點擊查看

構造圖片如下:
在這裏插入圖片描述

#include<bits/stdc++.h>
using namespace std;
void print(int x,int y){
	printf("%d %d\n",x,y);
}
int main()
{
	int n;
	cin >> n;
	cout << 3*n+4 << endl;//不需要最小
	print(1,1);
	print(1,2);
	int j = 1; 
	for(int i = 2; i <= n+1; ++i){
		print(i,j);
		print(i,j+1);
		print(i,j+2);
		j++;
	} 
	print(n+2,j);
	print(n+2,j+1); 
	return 0;
} 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章