Codeforces Gym 100623F Problem F. Fenwick Tree
来源:互联网 发布:nosql数据库入门 编辑:程序博客网 时间:2024/05/31 15:19
题目传送门:http://codeforces.com/gym/100623/attachments
题解:一个找规律的题,b[2]=a[2]要求a[1]=0,b[4]=a[4]要求a[2]+a[3]=0,b[6]=a[6]要求a[5]=0,b[8]=a[8]要求a[4]+a[6]+a[7]=0,到这里就可以看出来规律了,一个偶数可以对2^n取余为0,则要求他前面的n个数和为0,这个n个数的递减规律是1.1.2.4.8.16....2^n,这样,然后写一下就可以了
Code:
#include <iostream>#include <cstdio>using namespace std;int main(){ freopen("fenwick.in","r",stdin); freopen("fenwick.out","w",stdout); int t,n,flag; long long a[100005],sum; long long n2[16]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536}; long long b[16]={1,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384}; while(cin>>n) { for(int i=1;i<=n;i++) scanf("%lld",&a[i]); for(int i=2;i<=n;i+=2) { sum=0; flag=-1; t=i; for(int j=0;j<16;j++) { if(i%n2[j]==0) flag=j; else break; } for(int j=0;j<flag;j++) { t-=b[j]; sum+=a[t]; } t-=b[flag]; a[t]=-sum; } for(int i=1;i<=n;i++) i==n?cout<<a[i]<<endl:cout<<a[i]<<" "; } return 0;}
0 0
- Codeforces Gym 100623F Problem F. Fenwick Tree
- ACM ICPC 2008–2009, NEERC, Problem F Fenwick Tree(找规律,打表) Codeforces Gym 100623F
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- 【Codeforces Gym 100187F 】+ 贪心
- codeforces-gym-100187-F【贪心】
- Codeforces gym 101350F 想法
- Codeforces Gym 101142 F. Folding
- Codeforces Gym 101164 F. Letter
- [Gym-101350F] F
- codeforces gym 100342F Move to Front
- codeforces gym 101142 F(思维)
- Codeforces Gym 100642 C D F
- Codeforces Gym-101116-F (Flight Plan)
- Problem F CodeForces 16E
- CodeForces 762F. Tree nesting
- CodeForces 762F. Tree nesting
- linux下安装numpy
- LeetCode算法题目:Rotate List
- Nginx+upload+lua 简单的文件上传
- Spring Boot学习(一)
- 【JAVA】系统中关于自定义比例选择的功能实现
- Codeforces Gym 100623F Problem F. Fenwick Tree
- 微信小程序--Ble蓝牙
- iOS NSKeyedArchiver
- mysql大小写区分 lower_case_table_names与binary
- android_分享图片功能实现
- 汽车CAN总线关闭故障的诊断与恢复
- 学习C++的视频和书
- Freemarker模板应用
- java中Action层、Service层和Dao层的功能区分