Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
来源:互联网 发布:北京理工大学 网络教育 编辑:程序博客网 时间:2024/05/25 12:20
题意: 有多少个a[i]^a[j]=x,(1<=i<j<=n)
思路:因为 (1 ≤ ai ≤ 105) 所以想到用个数组标记下个数,找a[i]^x值有多少个,
才开始没考虑到x=0的情况,也忘了>,<运算符是优先与^的,后又因为标记的数组开的10^5开小了(两个数异或值可能大于这两个数),RE了,总之wa了很多遍终于过了,结果还是被hack掉了,因为只有结果开了long long,后来把数组也开的long long就过了
起初一直想着怎么去重,想法很复杂,后来发现直接找个数都重复一次,结果除以2就可以了
起初的code:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;long long vis[100005],a[100005];int main(){ int n,x; while(~scanf("%d%d",&n,&x)) { memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) { cin>>a[i]; vis[a[i]]++; } long long ans=0; sort(a,a+n); if(x==0) { for(int i=1; i<=100000; i++) { if(vis[i]>=2) ans+=vis[i]*(vis[i]-1)/2; } } else { for(int i=0; i<n; i++) { if((x^a[i])<=100000&&vis[x^a[i]]>0&&vis[a[i]]>0) { ans+=vis[x^a[i]]*vis[a[i]]; if(x^a[i]<a[i]) { vis[x^a[i]]=-1; } else { vis[a[i]]=-1; } } } } cout<<ans<<endl; }}
简单代码:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;int vis[1000005],a[100005];int main(){ int n,x; while(~scanf("%d%d",&n,&x)) { memset(vis,0,sizeof(vis)); for(int i=0; i<n; i++) { scanf("%d",&a[i]); vis[a[i]]++; } long long ans=0; for(int i=0; i<n; i++) { if(a[i]!=(x^a[i])) { ans+=vis[x^a[i]]; } else { ans+=vis[x^a[i]]-1; } } cout<<ans/2<<endl; }}
0 0
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution 数学
- Codeforces Round #383 (Div. 2) 742B Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces Round #383 (Div. 2) Arpa’s obvious problem and Mehrdad’s terrible solution 数学
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution(模拟)
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution 数论、易错
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution(STL乱搞)
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
- Codeforces Round #383 (Div. 2)B.Arpa’s obvious problem and Mehrdad’s terrible solutio【思维】
- Arpa’s obvious problem and Mehrdad’s terrible solution CodeForces
- Arpa’s obvious problem and Mehrdad’s terrible solution (CodeForces
- B. Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces 742B B. Arpa’s obvious problem and Mehrdad’s terrible solution
- 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution
- Codeforces 742B Arpa’s obvious problem and Mehrdad’s terrible solution(map水题)
- AWS发布基于Docker的Amazon Linux容器映像
- cesiumjs开发实践(一) 简介、开发环境搭建
- iOS打包ipa的四种方法(.app转.ipa)
- vs2015使用Oracle提供的ODT为RDLC报表添加数据集
- PHP ini_set()无效的原因
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
- iOS 6~10 UITableViewCell 之行高算式精要
- ARM的四种堆栈
- linux中的ssh安装、卸载与配置
- Oracle date 和 timestamp 区别
- Gradle xxx project refresh failed,Minimum supported Gradle的问题
- git hub的GUI软件配置与使用
- xml数据的获取和处理
- sed 命令的使用