• 【CF1017B】The Bits(模拟)


    题意:给定两个二进制数字a,b,可以任意交换a中的两个bit位,求进行这样一次操作,最多可产生多少种不同的a or b

    n<=1e5

    思路:模拟,分类讨论

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   110000
    21 #define MOD 1000000007
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 
    25 char a[N],b[N];
    26 
    27 int read()
    28 { 
    29    int v=0,f=1;
    30    char c=getchar();
    31    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    32    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    33    return v*f;
    34 }
    35 
    36 void swap(int &x,int &y)
    37 {
    38     int t=x;x=y;y=t;
    39 }
    40 
    41         
    42 int main()
    43 {
    44     //freopen("1.in","r",stdin);
    45     //freopen("1.out","w",stdout);
    46     int n;
    47     scanf("%d",&n);
    48     scanf("%s",a);
    49     scanf("%s",b);
    50     //printf("%s
    ",a);
    51     //printf("%s
    ",b); 
    52     ll ans=0;
    53     ll x=0;
    54     ll y=0;
    55     ll z=0;
    56     ll w=0;
    57     for(int i=0;i<=n-1;i++)
    58     {
    59          if(a[i]=='0'&&b[i]=='0') x++;
    60          if(a[i]=='1'&&b[i]=='0') y++;
    61          if(a[i]=='0'&&b[i]=='1') z++;
    62          if(a[i]=='1'&&b[i]=='1') w++;
    63     }
    64     ans=x*y+x*w+z*y;
    65     printf("%lld
    ",ans);
    66     return 0;
    67 }
  • 相关阅读:
    单例模式
    设计模式
    C#判断Textbox是否为数字
    C#判断输入的是否是汉字
    C#如何测试代码运行时间
    网上 server2008数据库恢复方法
    C# 控件的缩写
    SQLite主键自增代码
    Sqlite数据库联合查询及表复制等详述
    C#中超链接方法
  • 原文地址:https://www.cnblogs.com/myx12345/p/9843050.html
Copyright © 2020-2023  润新知