Educational Codeforces Round 70 (Rated for Div. 2)

这次真的好难......

我这个绿名蒟蒻真的要崩溃了555...

我第二题就不会写......

暴力搜索MLE得飞起。

好像用到最短路?然而我并没有学过,看来这个知识点又要学。

后面的题目赛中都没看,今天早上看了一下D发现还是能写的。

A.You Are Given Two Binary Strings...

简单来说,对f(y)乘以2的k次,实际上就是把这个串左移k位。要使反转的串的字典序最小,就要让f(y)最后的1与f(x)的最后的1的位置对齐。

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    while(n--) {
        string a,b;
        cin>>a>>b; 
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        int a1;
        int b1=b.find('1');
        for(int i=b1;i<a.length();i++)
        {
            if(a[i]=='1')
            {
                a1=i;
                break;
            }
        }
        if(a1<=b1)cout<<0<<'\n';
        else
        cout<<a1-b1<<'\n';

    }
    return 0;
}

D.Print a 1337-string...

 

构造问题,一步一步考虑:

扫描二维码关注公众号,回复: 6987561 查看本文章

先假设答案为“133X333333......7"(X是什么后面解释)

1.先考虑 '3',假设有n个‘3’,那么就会有Cn2 种情况(暂时不会latex...),当n为2,3,4...时,就会有1,3,6...种情况。

2.当输入的数ni不包括在Cn种(比如4,5)时,只需要计算出n与距离最近的Cn2  差值m,在答案中的X位置插入m个7即可。

举个例子:13

循环可知有4个3(n为4时有10种情况):“133X337" 。

差值为3所以往X的位置插入3个7,答案即为:”133777337“。

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        int i;
        for(i=1;(i*(i-1))/2<=a;i++);
        int n=i-1;
        int m=a-((n-1)*n)/2;
        cout<<"133";
        for(int i=0;i<m;i++)cout<<'7';
        for(int j=0;j<n-2;j++)cout<<'3';
        cout<<"7\n"; 
    }
    return 0;
 } 

之后学了最短路把b题补了

猜你喜欢

转载自www.cnblogs.com/wgqqq/p/11324967.html