ACM-ICPC (10/17)
今天满课啊,天气太冷了,网上找了一下虚树的东西,还没弄懂~~~(;´д`)ゞ
牛客网挑战赛1
输入描述:
第一行一个数n表示点的个数;
接下来n-1行,每行两个整数x,y表示边;
保证输入数据形成一棵树;
1<=n<=100000
输出描述:
一行一个整数表示答案。
输入
3
1 2
1 3
输出
1
分析:奇数层到奇数层,偶数层到偶数层。
题目描述
输入描述:
第一行一个数n表示数组长度;
第二行n个整数表示数组;
1<=n<=1000,0<=数组元素<100000。
输出描述:
一行一个整数表示答案。
输入
3
0 0 0
输出
5
说明
([1,1],[2,2]),([1,1],[3,3]),([1,1],[2,3]),([1,2],[3,3]),([2,2],[3,3])
又是一道异或题,涨姿势了~~~
网上有很多二分的方案,有一种很巧妙的遍历方式。
枚举中心轴,右区间做测试,左区间维护异或值。遍历左区间,从右到左记录~~~
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3+;
int a[maxn];
int sets[]; int main()
{
//freopen("in.txt","r",stdin); int n;
cin>>n; for(int i = ; i <= n; i++) scanf("%d",&a[i]); long long cnt = ;
for(int i = ; i <= n; i++) {
int s = ;
for(int j = i; j <=n; j++) {
s^=a[j];
cnt+=sets[s];
}
s = ;
for(int j = i; j >= ; j--) {
s^=a[j];
sets[s]++;
}
}
printf("%lld\n",cnt); return ;
}
ACM-ICPC (10/17)的更多相关文章
- 2011 ACM/ICPC 成都赛区(为2013/10/20成都现场赛Fighting)
hdu 4111 Alice and Bob 博弈:http://www.cnblogs.com/XDJjy/p/3350014.html hdu 4112 Break the Chocolate ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))
祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- mysql PXC集群方案总结
同时写集群内的所有机器 写性能依赖最慢的那个机器 读性能提高X倍
- 使用Redis 配置替换fastjson 反序列化报错 com.alibaba.fastjson.JSONException: autoType is not support
新建的GenericFastJson2JsonRedisSerializer里面添加白名 添加: static { ParserConfig.getGlobalInstance().ad ...
- [转]how to use both JDK 7 and JDK 8 in one build
Note: This article is original from https://gist.github.com/aslakknutsen/9648594 JDK 8 Released Most ...
- opensuse 安装oracle 界面乱码
执行.runInstall时,出现界面乱码 export LANG=en_US export LC_ALL=en_US 终端里 执行这两句.用英文界面安装 再执行 .runInstall
- cmd激活win10
自己动手,KMS激活win10 2016 长期服务版.步骤如下:命令提示符(管理员),依次输入以下3条命令 slmgr /ipk DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJslmgr ...
- js数据类型检测小结
在js中,有四种用于检测数据类型的方式,分别是: typeof 用来检测数据类型的运算符 instanceof 检测一个实例是否属于某个类 constructor 构造函数 Object.protot ...
- UiPath进阶
最近RPA比较火,UiPath工具排名前几位并且免费试用,很多朋友们都选择了学习自动化工具UiPath,今天我就向大家介绍一下UiPath的学习过程,希望对后来的学习这个工具的人有所帮助. UiPat ...
- Log4j和Slf4j的比较
简单日记门面(simple logging Facade for java)SLF4J是为各种loging APIs提供一个简单统一的接口,从而使得最终用户能够在部署的时候配置自己希 望的loging ...
- [LeetCode]21. Merge Two Sorted Lists合并两个有序链表
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- SQLAlchemy的使用---数据库的创建与连接
# 1. 导入SQLAlchemy from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Col ...