UPC 2017 Summer Training 1
来源:互联网 发布:oracle数据库审计 编辑:程序博客网 时间:2024/05/19 06:47
I - Salem
Salem is known to be one of the best competitive programmers in the region. However, he always finds a hard time understanding the concept of the hamming distance. The hamming distance of two numbers is defined as the number of different digits in their binary representations (leading zeros are used if necessary to make the binary representations have the same length). For example the hamming distance between 12 and 5 is 2 since their binary representations are 1100 and 0101 respectively and they differ in the first and fourth positions.
Recently, Salem got a problem that he needs your help to solve. He is given Nintegers and asked to get the maximum among the hamming distances of all possible pairs of the given integers.
The first line of the input will be a single integer T representing the number of test cases. Followed by T test cases. Each test case will start with a line with single integer (2 ≤ N ≤ 100) representing the number of the integers. Each of the following N lines contains one of the integers (1 ≤ Ai ≤ 10, 000) from the list of the integers.
For each test case print one line consists of one integer representing the maximum hamming distance between all possible pairs from the given integers.
221253123
22
#include<stdio.h>#include<string.h>int max(int a,int b){return a>b?a:b;}int p(int aa,int bb)//判断比较 简单暴力{int sum=0;while(aa!=0 || bb!=0){int temp=aa%2;aa=aa/2;int temp1=bb%2;bb=bb/2;if(temp!=temp1){sum++;}}return sum;} int main(){int maxx,sum;int n,m;int l[2000];while(scanf("%d",&n)!=EOF){while(n--){scanf("%d",&m);sum=0;for(int i=0;i<m;i++)scanf("%d",&l[i]);for(int i=0;i<m-1;i++){for(int j=i+1;j<m;j++){maxx=p(l[i],l[j]); sum=max(sum,maxx);}}printf("%d\n",sum);}}return 0; }PS:开全局数组传递数值,别传递坐标,改变值~
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 1
- UPC 2017 Summer Training 5
- UPC 2017 Summer Training 5
- UPC 2017 Summer Training 6 A,D,I
- UESTC 2017 Summer Training #1 Div.2
- BUPT 2017 summer training (for 16) #1
- 2017 Summer Training Day1
- BUPT Summer training 1 总结
- SDKD 2017 Summer Single Training #01(训练赛1)
- 2017 Xian ACM Summer Training Warm-up Exercise 1
- UESTC 2017 Summer Training #2 Div.2
- E- Refraction----(2015 NEUQ_ACM summer training #1)
- ecjtu-summer training #1 F (UVA 11461)
- Tri_integral Summer Training 6
- BUPT-SUMMER-TRAINING-搜索
- 数据类型的最大最小值
- String to others
- 小希的迷宫||HDU1272
- 集合框架——可变参数、静态导入
- Zeppelin源码分析-独立解释器 JVM 相关分析(3)
- UPC 2017 Summer Training 1
- JS中的数组
- Java多线程基础--07之 线程休眠
- 257. Binary Tree Paths
- C++内置函数(内嵌函数,内联函数)
- Tomcat 部署 Spring mvc 失败
- Zeppelin源码分析-独立解释器 JVM 相关分析(4)
- Django静态资源和模板配置
- Find The Multiple