加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【CF1017B】The Bits(模拟)

发布时间:2020-12-14 04:17:42 所属栏目:大数据 来源:网络整理
导读:题意:给定两个二进制数字 a,b ,可以任意交换 a 中的两个bit位,求进行这样一次操作,最多可产生多少种不同的 a or b n=1e5 思路:模拟,分类讨论 1 #includecstdio 2 #includecstring 3 #include string 4 #includecmath 5 #includeiostream 6 #includealg

题意:给定两个二进制数字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("%sn",a);
51     //printf("%sn",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("%lldn",ans);
66     return 0;
67 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读