zoukankan      html  css  js  c++  java
  • 【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 }
  • 相关阅读:
    段错误诊断!
    kissthank
    c实现面向对象编程(3)
    字符串转换成数字以及注意事项
    【Java并发编程实战】-----“J.U.C”:CLH队列锁
    c编程:僵尸吃大脑
    展示C代码覆盖率的gcovr工具简单介绍及相关命令使用演示样例
    最优化学习笔记(三)最速下降法
    maven学习
    ASP.NET MVC 入门4、Controller与Action
  • 原文地址:https://www.cnblogs.com/myx12345/p/9843050.html
Copyright © 2011-2022 走看看