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 ...
随机推荐
- 【洛谷 P3899】 [湖南集训]谈笑风生 (主席树)
题目链接 容易发现\(a,b,c\)肯定是在一条直链上的. 定义\(size(u)\)表示以\(u\)为根的子树大小(不包括\(u\)) 分两种情况, 1.\(b\)是\(a\)的祖先,对答案的贡献是 ...
- PACM Team(牛客第三场多校赛+dp+卡内存+打印路径)
题目链接(貌似未报名的不能进去):https://www.nowcoder.com/acm/contest/141/A 题目: 题意:背包题意,并打印路径. 思路:正常背包思路,不过五维的dp很容易爆 ...
- js_setCookie,getCookie和checkcookie函数
随便说说: cookie和sessionStrong,localStrong在web应用中都有一种存储的功能,也就是说可以把一些数据记录在浏览器.cookie和后两者的主要区别 是cookie是和后端 ...
- 3.0docker操作
登录镜像资源 docker login daocloud.io username: password: docker login : 登陆到一个Docker镜像仓库,如果未指定镜像仓库地址,默认为官方 ...
- 排序中topK那点事(转)
问题描述:有 N (N>1000000)个数,求出其中的前K个最小的数(又被称作topK问题). 这类问题似乎是备受面试官的青睐,相信面试过互联网公司的同学都会遇到这来问题.下面由浅入深,分析一 ...
- mysql中的enum型
enum设置后 值只能是给出的值中的其中一个 mysql> create table enum(e enum('1','2','3','4','5','6','7','8','9','10')) ...
- linux加载指定目录的so文件
linux加载指定目录的so文件 http://blog.csdn.net/win_lin/article/details/8286125 download urlhttp://download.ch ...
- 菜鸟进阶之:VC++之Visual Studio中DLL调用实现
C++写的DLL,用C++调用其实是一个比较简单的事情,调用DLL函数的方法其实有很多,说一个最普通的方法: 1.新建一个解决方案,文件->新建项目->Visual c++->win ...
- 微信小程序宽高适配
小程序的宽任何机型都是750rpx,但是画布canvas的默认单位是px,可能会出现需要怪异的样式,我们可以用到 wx.getSystemInfoSync().windowWidth和 wx.getS ...
- 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]
首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...