Codeforces Round #594 (Div. 2)(A/B/C)
A. Integer Points
Description
DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew n distinct lines, given by equations y=x+pi for some distinct p1,p2,…,pn. Then JLS drew on the same paper sheet m distinct lines given by equations y=−x+qi for some distinct q1,q2,…,qm . DLS and JLS are interested in counting how many line pairs have integer intersection points, i.e. points with both coordinates that are integers. Unfortunately, the lesson will end up soon, so DLS and JLS are asking for your help.
Input
The first line contains one integer t(1≤t≤1000
1≤t≤1000), the number of test cases in the input. Then follow the test case descriptions. The first line of a test case contains an integer n (1≤n≤1051≤n≤105), the number of lines drawn by DLS.The second line of a test case contains n distinct integers pipi (0≤pi≤1090≤pi≤109) describing the lines drawn by DLS. The integer pi describes a line given by the equation y=x+piy=x+pi. The third line of a test case contains an integer m (1≤m≤1051≤m≤105), the number of lines drawn by JLS. The fourth line of a test case contains m distinct integers qiqi (0≤qi≤1090≤qi≤109) describing the lines drawn by JLS. The integer qi describes a line given by the equation y=−x+qi
y=−x+qi . The sum of the values of n over all test cases in the input does not exceed 105. Similarly, the sum of the values of m over all test cases in the input does not exceed 105 . In hacks it is allowed to use only one test case in the input, so t=1 should be satisfied.
Output
For each test case in the input print a single integer — the number of line pairs with integer intersection points.
Example
Input
3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1
Output
3
1
0
Note
The picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates.
解体思路:容易想到的是利用x=(q-p)/2,y=(p+q)/2,对所有交点进行判断是否为整数,很明显由于数据量过大,超时。第二种方法,通过画图,寻找规律,可以发现当p,q同时为奇数或偶数的时候,交点为整数点。结果需要用long long 存下。
TE代码:
#include <iostream>
#include <cmath>
using namespace std;
double a[];
double b[];
int main()
{
int t,n,m;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
cin>>m;
for(int i=;i<m;i++)
cin>>b[i];
int k=;
int cnt=;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
long double tx=(b[j]-a[i])/;
long double ty=(a[i]+b[j])/;
long long tmpx=(long long)(b[j]-a[i])/;
long long tmpy=(long long)(a[i]+b[j])/;
if(fabs(ty-tmpy)<1e-&&fabs(tx-tmpx)<1e-&&(long long)(a[i]+b[j])%==)
cnt++;
}
}
cout<<cnt<<endl;
}
return ;
}
AC代码:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long long t,n,m,sum1,sum2,sum3,sum4,p,q;
cin>>t;
while(t--)
{
cin>>n;
sum1=sum2=sum3=sum4=;
for(int i=;i<n;i++)
{
cin>>p;
if(p%==)
sum1++;
else
sum2++;
}
cin>>m;
for(int i=;i<m;i++)
{
cin>>q;
if(q%==)
sum3++;
else
sum4++;
}
cout<<sum1*sum3+sum2*sum4<<endl;
}
return ;
}
Codeforces Round #594 (Div. 2)(A/B/C)的更多相关文章
- Codeforces Round #594 (Div. 2)
传送门 C. Ivan the Fool and the Probability Theory 题意: 给出一个\(n*m\)的方格,现在要给方格中的元素黑白染色,要求任一颜色最多有一个颜色相同的格子 ...
- Codeforces Round #594 (Div. 1) D. Catowice City 图论
D. Catowice City In the Catowice city next weekend the cat contest will be held. However, the jury m ...
- Codeforces Round #594 (Div. 1) C. Queue in the Train 模拟
C. Queue in the Train There are
- Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维
D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...
- Codeforces Round #594 (Div. 2) B. Grow The Tree 水题
B. Grow The Tree Gardener Alexey teaches competitive programming to high school students. To congrat ...
- Codeforces Round #594 (Div. 2) A. Integer Points 水题
A. Integer Points DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS to ...
- Codeforces Round #594 (Div. 1) A. Ivan the Fool and the Probability Theory 动态规划
A. Ivan the Fool and the Probability Theory Recently Ivan the Fool decided to become smarter and stu ...
- Codeforces Round #594 (Div. 1)
Preface 这场CF真是细节多的爆炸,B,C,F都是大细节题,每道题都写了好久的说 CSP前的打的最后一场比赛了吧,瞬间凉意满满 希望CSP可以狗住冬令营啊(再狗不住真没了) A. Ivan th ...
- B. Grow The Tree Codeforces Round #594 (Div. 2)
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on t ...
随机推荐
- 返回vector指针
#include<iostream> #include <vector> using namespace std; vector<int> *MyFind() { ...
- 服务消费(LoadBalancerClient、Ribbon、Feign)
转自:https://www.jianshu.com/p/562045489d9d 4.1使用LoadBalancerClient 在Spring Cloud Commons中提供了大量的与服务治理相 ...
- [React] Always useMemo your context value
Have a similar post about Reac.memo. This blog is the take away from this post. To understand why to ...
- BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡 概率与期望+高斯消元
这个还挺友好的,自己相对轻松能想出来~令 $f[i]$ 表示起点到点 $i$ 的期望次数,则 $ans[i]=f[i]\times \frac{p}{q}$ #include <cmath> ...
- HZOJ 20190719 那一天我们许下约定(dp+组合数)
这个题目背景真的是让我想起了当年... 不说了,言归正传,这题,一眼看去30分暴力还是很好拿的,但我因为考试时的心态问题没有处理好细节爆了零. 30分暴力的普遍思路的复杂度应该是$O(nmd)$的,但 ...
- Python与开源GIS
https://www.osgeo.cn/pygis/ 这里列出了与 GIS 相关的 Python 开源类库与工具. 基础类库(抽象库) • GDAL/OGR 是大部分开源GIS的基础,也包括如Arc ...
- JS基础_toString()
当我们直接在页面中打印一个对象时,实际上是输出的对象的toString()方法的返回值 如果我们希望在输出对象时不输出[ object Object ],可以为对象添加一个toString()方法或者 ...
- mybatis延迟加载(assocation)
一.何为延迟加载? 延迟加载 我们并不需要总是在加载用户信息时就一定要加载他的账户信息.此时就是我们所说的延迟加载. 就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据.延迟加载也称懒加载. ...
- LeetCode 130. 被围绕的区域(Surrounded Regions)
题目描述 给定一个二维的矩阵,包含 'X' 和 'O'(字母 O). 找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O' 用 'X' 填充. 示例: X X X X X O O X X X ...
- Python做域用户验证登录
安装包 ldap3 代码: from ldap3 import Server, Connection, ALL, NTLM # 连接 server = Server('public.ad.com', ...