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;
}