Codeforces Round #554 (Div. 2)

B. Neko Performs Cat Furrier Transform
题目链接:https://codeforces.com/contest/1152/problem/B
思路:将数转化成二进制,每次遍历一遍,遇到0就操作一次,然后更新。。。
AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[50];
int b[50];
void aaa(int xx)
{
     int tmp=0;
     while(xx)
     {
          a[++tmp]=xx%2;
          xx/=2;
     }
     for(int i=tmp;i>0;i--)
     {
          b[i]=a[tmp-i+1];
     }
}
int main()
{
     int x;
     scanf("%d",&x);
     int xx=x;
     int tmp=0;
     while(xx)
     {
          a[++tmp]=xx%2;
          xx/=2;
     }
     for(int i=tmp;i>0;i--)
     {
          b[i]=a[tmp-i+1];
     }
     int sum[50];
     int tt=0;
     int ans=0;
     int xxx=x;
     int cnt=0;
     int i,j;
     int flag=0;
     for(i=1;i<=40;i++){
     for(j=1;j<=tmp;j++)
     {

          if(!b[j]&&cnt%2==0)
          {
              int t1=pow(2,tmp-j+1);
              x=x^(t1-1);
              aaa(x);
              sum[tt++]=tmp-j+1;
              cnt++;
              break;
          }
          if(!b[j]&&cnt%2==1)
          {
              x+=1;
              aaa(x);
              cnt++;
              break;
          }
          if(j==tmp)
          {
            flag=1;
            break;
          }
     }
         if(flag==1)
         {
             break;
         }
     }
     if(xxx==0)
          cnt=0;
          printf("%d\n",cnt);
          for(i=0;i<tt;i++)
          {
              printf("%d ",sum[i]);
          }
          if(tt)
          printf("\n");
     return 0;
}
/*
Input
39
Output
4
5 3 
Input
1
Output
0
Input
7
Output
0
*/

C. Neko does Maths
题目链接:https://codeforces.com/contest/1152/problem/C
题目大意:给定两个数a,b,求出使得公倍数lcm(a+k,b+k)最小的k值,数据范围1e9。
最无脑暴力解超时。。。。
AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mul(ll a,ll b)
{
      ll aa=a;
      ll bb=b;
      int minn=aa;
      while(minn>0)
      {
          minn=(aa+bb-minn)%minn;
          bb=aa;
          aa=minn;
      }
      return a*b/bb;
}
ll gcd(ll a,ll b)
{
     if(b==0)
          return a;
     return gcd(b,a%b);
}
int main()
{
     ll a ,b;
     scanf("%lld%lld",&a,&b);
     ll k=0;
     ll ans=0;
     if(a>b)
          swap(a,b);
     ll maxx=mul(a,b);
     ll len=b-a;
     for(ll i=1;i*i<=len;i++)
     {
          if(len%i==0)
          {
               ll t1=(i-a%i)%i;
               ll tmp=mul(a+t1,b+t1);
               if(tmp<maxx||(tmp==maxx&&ans>t1))
               {
                    ans=t1;
                    maxx=tmp;
               }
               ll tt=len/i;
               ll t2=(tt-a%tt)%tt;
               ll tmp2=mul(a+t2,b+t2);
               if(tmp2<maxx||(tmp2==maxx&&ans>t2))
               {
                    ans=t2;
                    maxx=tmp2;
               }
          }
     }
     cout<<ans<<endl;
     return 0;
}
/*
Input
6 10
Output
2
Input
21 31
Output
9
Input
5 10
Output
0
*/

D. Neko and Aki’s Prank
题目链接:https://codeforces.com/contest/1152/problem/D
AC代码:

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxx=2005;
int dp[maxx][maxx];
void solve()
{
     for(int i=1;i<=1000;i++)
     {
          dp[i][0]=(i+1)/2;
     }
     for(int i=1;i<=1000;i++)
     {
          for(int j=1;j<=i;j++)
          {
                int tmp=(dp[i-1][j]+1)%mod;
                if(i-1>=0&&j-1>=0)
                {
                    tmp=(tmp+dp[i-1][j-1])%mod;
                }
                if(j-2>=0)
                {
                    tmp=(tmp+dp[i][j-2])%mod;
                }
                dp[i][j]=tmp;
          }
     }
}
int main()
{
     int n;
     scanf("%d",&n);
     solve();
     printf("%d\n",dp[n][n]);
     return 0;
}
/*
Input
1
Output
1
Input
2
Output
3
Input
3
Output
9
*/

我一定可以的!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值