Codeforces Round #448(Div.2) Editorial ABC
被B的0的情况从头卡到尾。导致没看C,心情炸裂又掉分了。
A. Pizza Separation
1 second
256 megabytes
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
4
90 90 90 90
0
3
100 100 160
40
1
360
360
4
170 30 150 10
0
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:

Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std;
const int N=;
int a[N],n,m,all,mindif;
set<int> num,num2;
set<int>::iterator it;
int main()
{
scanf("%d",&n);
all=;
mindif=INF;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<=n;i++)
{
all=;
for(int j=i;j<=i+n;j++)
{
all+=a[(j-)%n+];
if(abs(-*all)<mindif)
mindif=abs(-*all);
}
}
printf("%d\n",mindif);
return ;
}
B. XK Segments
1 second
256 megabytes
standard input
standard output
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes(i, j) such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x.
In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).
The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Print one integer — the answer to the problem.
4 2 1
1 3 5 7
3
4 2 0
5 3 1 7
4
5 3 1
3 3 3 3 3
25
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.
题意:
把左右区间端点分开,那么[l,r]整除x的数的数量为r/x-(l-1)/x。读入的时候把他们(r/x 和(l-1)/x)加入对应的map l和r 中,然后用迭代器it遍历r的map,找对应的 l 中 it->first -k 的数量乘上it->second的数量加入答案中即可。
然后要特判下0的情况,0的话把所有数都加入一个map中,然后遍历这个map,对于每个map对,把他的it->second乘上它前面first/x值为it->first/x的对的个数为答案的贡献。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
map<LL,LL> r,l,a;
map<LL,LL>::iterator it;
LL x,k;
int n,m,p;
LL ans,num;
int main()
{
scanf("%d%I64d%I64d",&n,&x,&k);
for(int i=;i<=n;i++)
{
scanf("%I64d",&num);
l[(num-)/x]++;
r[num/x]++;
a[num]++;
}
ans=;
if(k==)
{
p=;
k=;
m=;
for(it=a.begin();it!=a.end();it++)
{
m+=(int)it->second;
if( it->first/x > k)
{
p=m;
if( it->first % x !=)
p-=(int)it->second;
}
k=it->first/x;
ans+=(LL)(m-p) * it->second;
}
printf("%I64d\n",ans);
return ;
}
for(it=r.begin();it!=r.end();it++)
ans+=l[it->first-k]*it->second;
printf("%I64d\n",ans);
return ;
}
C. Square Subsets
4 seconds
256 megabytes
standard input
standard output
Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.
Two ways are considered different if sets of indexes of elements chosen by these ways are different.
Since the answer can be very large, you should find the answer modulo 109 + 7.
First line contains one integer n (1 ≤ n ≤ 105) — the number of elements in the array.
Second line contains n integers ai (1 ≤ ai ≤ 70) — the elements of the array.
Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo109 + 7.
4
1 1 1 1
15
4
2 2 2 2
7
5
1 2 4 5 8
7
In first sample product of elements chosen by any way is 1 and 1 = 12. So the answer is 24 - 1 = 15.
In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.
题意:
给你n个≤70的数,问有几种取数方式能使取出来的数乘积为完全平方数。
题解:
考虑70内的质因子只有19个。那么每个数字都能表示为19维的01向量,每一维表示该位质因子在该数出现的幂次的奇偶。1为奇0为偶。把他转换为一个二进制数。
那么数的乘积为完全平方数就相当于取这n个19维的01向量的一个组合,使得xor结果为0。
那么写个最高19位的线性基,然后看看线性基里大于0的数的个数lct。答案即为$ 2^{n-lct}-1 $,这是线性基中组合出现相同数的一个结论。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
const int M=1e2+;
const LL mod=1e9+;
int prime[M],inf[M],pcnt,n,m,k,p,t;
int liner[],lcnt;
LL quick_pow(LL x,LL n)
{
LL res=;
x%=mod;
while(n)
{
if(n&)
res=(res*x)%mod;
n>>=;
x=(x*x)%mod;
}
return res;
}
void init()
{
clr(inf);
pcnt=;
lcnt=;
for(int i=;i<=;i++)
{
if(!inf[i])
{
prime[++pcnt]=i;
inf[i]=;
}
for(int j=;j<=pcnt;j++)
{
if(i>/prime[j]) break;
inf[prime[j]*i]=;
if(i%prime[j]==) break;
}
}
clr(liner);
return ;
}
int main()
{
init();
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&p);
k=;
for(int j=;j<=pcnt;j++)
{
k<<=;
while(!(p%prime[j]))
{
k^=;
p/=prime[j];
}
}
for(int j=pcnt;j>=;j--)
{
if(k>>j)
{
if(liner[j]) k^=liner[j];
else
{
liner[j]=k;
break;
}
}
}
}
for(int i=pcnt;i>=;i--)
if(liner[i])
{
lcnt++;
}
printf("%lld\n",(quick_pow(,(LL)(n-lcnt))-+mod)%mod);
return ;
}
Codeforces Round #448(Div.2) Editorial ABC的更多相关文章
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #747 (Div. 2) Editorial
Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...
- Codeforces Round #544 (Div. 3) Editorial C. Balanced Team
http://codeforces.com/contest/1133/problem/Ctime limit per test 2 secondsmemory limit per test 256 m ...
- Codeforces Round #710 (Div. 3) Editorial 1506A - Strange Table
题目链接 https://codeforces.com/contest/1506/problem/A 原题 1506A - Strange Table Example input 5 1 1 1 2 ...
- Codeforces Round #453 ( Div. 2) Editorial ABCD
A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #448 (Div. 2) B
题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样 可以看出对于每个数字a 都能够二分 ...
- Codeforces Round #448 (Div. 2)C. Square Subsets
可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异 ...
- Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- POJ 2533 Longest Ordered Subsequence LIS O(n*log(n))
题目链接 最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列. #include <iostream> #include <algorithm> using ...
- 【洛谷 P4320】 道路相遇 (圆方树,LCA)
题目链接 题意:给一张无向图和\(M\)个询问,问\(u,v\)之间的路径的必经之点的个数. 对图建出圆方树,然后必经之点就是两点路径经过的原点个数,用\((dep[u]+dep[v]-dep[LCA ...
- Can you answer these queries?(HDU4027+势能线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...
- 4 Values whose Sum is 0 POJ 2785 (折半枚举)
题目链接 Description The SUM problem can be formulated as follows: given four lists A, B, C, D of intege ...
- react组件之间的几种通信情况
组件之间的几种通信情况 父组件向子组件通信 子组件向父组件通信 跨级组件通信 没有嵌套关系组件之间的通信 1,父组件向子组件传递 React数据流动是单向的,父组件向子组件通信也是最常见的;父组件通过 ...
- NodeJS中Buffer模块详解
一,开篇分析 所谓缓冲区Buffer,就是 "临时存贮区" 的意思,是暂时存放输入输出数据的一段内存. JS语言自身只有字符串数据类型,没有二进制数据类型,因此NodeJS提供了一 ...
- 一种通过HTTP传文件出网的姿势
在外网机器上运行文件服务接收服务 root@kali:~/pentest-script/FileTransfer/HttpServer# python3 SimpleHttpUpload.py Ser ...
- arduino 用电位器调节LED闪烁频率
int dianwei; int led = 13; void setup() { // put your setup code here, to run once: Serial.begin(9 ...
- Python标准库笔记(1) — string模块
String模块包含大量实用常量和类,以及一些过时的遗留功能,并还可用作字符串操作. 1. 常用方法 常用方法 描述 str.capitalize() 把字符串的首字母大写 str.center(wi ...
- Linux内核【链表】整理笔记(2) 【转】
转自:http://blog.chinaunix.net/uid-23069658-id-4725279.html 关于链表我们更多时候是对其进行遍历的需求,上一篇博文里我们主要认识了一下和链表操作比 ...