[补题|题解] Codeforces Round #739 (Div. 3)

A. Dislike of Threes

预处理 可能的数组就可以直接过

B.Who’s Opposite?

分类讨论一下

  • 不可能的情况
  1. 利用关系反过来求 a–>b 矛盾
  2. 最大节点比要求节点还大
#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
int num[N];
void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    int x = abs(a-b);
 
    if(x*2 < max(a,b))
    {
        cout<<-1<<endl;
        return;
    }
    if((1+x)*2-2 < c)
    {
        cout<<-1<<endl;
        return;
    }
 
 
    int d = 0 ;
    if(c+x>(x*2))
    d = (c+x)%(x*2);
    else
    d = c+x;
 
    cout<<d<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t -- )
    solve();
    return 0;
}

C. Infinity Table

卡我好久 只发现了 1 3 5 7 的规律
没想到是行的规律, 第一列的开方即是行数
下一次一定不在找 个数的关系了 应该直接找行数的关系

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
    ll n,x,y;
    cin>>n;
    
    if(n == 1)
    {
        cout<<1<<" "<<1<<endl;
        return;
    }
    
    ll p = sqrt(n);
    if(p*p!=n) p++;
    
    if(p*p - n < p)
    {
        x = p ;
        y = p*p - n +1;
    }
    else
    {
        y  = p ;
        x = n - (p-1)*(p-1);
    }
    cout<<x<<" "<<y<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t -- )
    solve();
    return 0;
}

D.Make a Power of Two

预处理 2^n 次幂 然后找到 两个字符串不同的个数

最后对这个求minn即是答案

D1.CODE 手动预处理+复杂的判断

这个预处理太麻烦了,而且后面的p1++还绕了我好久QAQ

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
char s[30];
char two[63][20]={"1","2","4","8","16","32","64","128","256","512","1024","2048","4096","8192","16384","32768","65536","131072","262144","524288","1048576","2097152","4194304","8388608","16777216","33554432","67108864","134217728","268435456","536870912","1073741824","2147483648","4294967296","8589934592","17179869184","34359738368","68719476736","137438953472","274877906944","549755813888","1099511627776","2199023255552","4398046511104","8796093022208","17592186044416","35184372088832","70368744177664","140737488355328","281474976710656","562949953421312","1125899906842624","2251799813685248","4503599627370496","9007199254740992","18014398509481984","36028797018963968","72057594037927936","144115188075855872","288230376151711744","576460752303423488","1152921504606846976","2305843009213693952","4611686018427387904"};
void solve()
{
    cin>>s;
    int n  = strlen(s),ans = INF;

    for(int i=0;i<=62;i++)
    {
        int re = 0 ,p1 = 0 ,p2 = 0 ;
        int len =strlen(two[i]);

        while(p1<n && p2<len)
        {
            if(s[p1] == two[i][p2])p1++,p2++;
            else p1++;
        }

        re = n-p2;
        if(p2<len) ///需要多减去的
            re+=len-p2;
        ans = min(ans,re);
    }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t -- )
    solve();
    return 0;
}
D2.CODE 位移预处理+简单判断

to_string 可以直接将 数字变成字符串

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
string str[100];

///str[i],s
int glen(string b,string a)
{
    int j = 0 ;
    int lena  = a.size();
    int lenb = b.size();

    for(int i=0;i<lena;i++)
    {
        if(j == lenb)
            break;
        if(a[i] == b[j])
            j++;
    }
    return lena + lenb - 2*j;///不同的地方
}
void init()
{
    ll now = 1;
    for(int i =0 ; i<=60; i++)
        str[i] = to_string(now<<i);
}
void solve()
{

    cin>>s;
    int res = 100;
    for(int i=0;i<=60;i++)
    res = min(res,glen(str[i],s));
    cout<<res<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    init();
    int t;
    cin>>t;
    while(t -- )
        solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值