首页 技术 正文
技术 2022年11月20日
0 收藏 901 点赞 4,265 浏览 1154 个字

【题目链接】:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2133

【题意】

【题解】

考虑每一个二进制数的最高位->第i位;

肯定是1(这里不讨论0的情况)

然后对于其余n-1个二进制数;

如果它们在第i位和它一样->也是1的话,那么异或结果是0

那么不管第i位后面的位怎么变;它肯定是变小的->我们要求的

如果它们在第i为和它不一样->即为0,那么异或结果是1;

则它肯定是变大了;

综上

我们只要确定每个数的最高位所在的位置i

然后确定其他数字在第i位上是为1的数的个数cnt;

然后加上cnt就好;

【Number Of WA】

0

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x)typedef pair<int,int> pii;
typedef pair<LL,LL> pll;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100;int T,n,m,top[N],tot[N];
LL ans;
string s;int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
cin >> T;
while (T--)
{
ans = 0;
cin >> n >> m;
rep1(j,1,m) tot[j] = 0;
rep1(i,1,n) top[i] = 0;
rep1(i,1,n)
{
cin >> s;
bool fi = true;
rep1(j,1,m)
{
if (s[j-1]=='1')
{
if (fi) top[i] = j,fi = false;
tot[j]++;
}
}
}
rep1(i,1,n)
ans+=tot[top[i]];
cout << ans << endl;
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,030
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,147
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859