题意:有\(n\)个数,你可以任意去除某个位置的元素然后得到一个新数组,使得新数组奇数位和偶数的元素相等,现在问你有多少种情况合法. 题解:先求个后缀和,然后遍历,记录奇数和偶数位置的前缀和,删去\(i\)位置的元素,意味着原来\(i\)位置之后的奇数和变成了偶数和,偶数和变成了奇数和,将前缀和与差位的后缀和相加判断一下即可. 代码: int n; ll a[N]; ll suf1[N],suf2[N]; ll cnt1,cnt2; int main() { ios::sync_with_std…
Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai. She plans to eat exactly n−1n−1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day. You…
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选一些题来写吧. B. Tanya and Candies 题意: 在n个数中任意删去一个,如果这个数被删去后,剩余数的奇数和以及偶数和相等,那么就定义这个数为"好数".现在问这n个数中有多少个“好数”. 题解: 预处理出奇数前缀和.偶数前缀和,删去一个数后所有的奇数位置和 就为前面的奇数和…
A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n,a,b,m; cin>>n; ;i <= n;i ++){ cin>>m>>a>>b; <= b) cout<<m*a…
D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508/problem/D Description While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a stri…
C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collectio…
C. Tanya and Toys 题目连接: http://www.codeforces.com/contest/659/problem/C Description In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new col…
https://codeforces.com/contest/1118/problem/C 在查找元素的时候,必须按4,2,1的顺序进行.因为,如果先找1,可能就把原来的4拆散了,然后再找4,就找不到了 #include<bits/stdc++.h> using namespace std; ][]; int main(){ int n; cin>>n; map<int,int> mp; int t; ;i<n*n;i++){ cin>>t; mp[t…
https://codeforces.com/contest/1118/problem/F1 #include<bits/stdc++.h> using namespace std; int n; vector<int> color; vector<vector<int> > tree; ,blue=; ; pair<){ ); ); ;i<tree[v].size();i++){ int u=tree[v][i]; if(u!=p){//避免回…
https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在这里采用binary search就可以了 #include<bits/stdc++.h> using namespace std; int n,m; vector<int> num; int C(int d){ ; ;i<n;i++){ sum+=max(num[i]-i/d,…