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 ...
随机推荐
- H5微信分享相关规范
微信分享 用户调用微信的分享功能,可以自定义分享的title和描述,以及小图标和链接.可以分享到群.好友.朋友圈.QQ.QQ空间等. 分享设计规范 分享标题:14字以内,建议使用朋友般亲切的口吻 分享 ...
- tornado框架自定义中间件过程中的一些基础技术(1)
为了检查当前请求是否在用户的权限列表中,我们需要获取uri(也就是当前链接),下列代码说明了获取的过程,也证明了python魔术方法的重要性class testHandler(RequestHandl ...
- python3爬虫--shell命令的使用和firefox firebug获取目标信息的xpath
scrapy version -v #该命令用于查看scrapy安装的相关组件和版本 一个工程下可创建多个爬虫 scrapy genspider rxmetal rxmetal.com scrapy ...
- hdu 6046 hash
题: OwO http://acm.hdu.edu.cn/showproblem.php?pid=6046 (2017 Multi-University Training Contest - Team ...
- 【Winfrom-TreeView】 跟随系统改变Style
C#: public class NativeTreeView : System.Windows.Forms.TreeView { [DllImport("uxtheme.dll" ...
- xcode打正式包提示缺少icon图标解决方法
报如下错,是说缺少ipad图标 解决方法 如下图创建图标库 打开新建的图标库文件夹中的contents.josn文件,把下面的代码复制到原来的图标库(可以不进行上一步建图标库,手动添加也可以) 然后把 ...
- Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法
Laravel dingo,HTTP的请求头(accept)无法携带版本号的解决方法 2017年9月6日 原创分享 zencodex 使用 Laravel dingo 做api开发时,涉及 A ...
- python测试网站访问速度
# -*- coding: utf-8 -*- # @Author : Felix Wang # @time : 2018/8/13 22:13 # pip3 install pycurl impor ...
- flask框架(十一): 蓝图
蓝图用于为应用提供目录划分: 一:上目录结构 二:上代码 <!DOCTYPE html> <html lang="en"> <head> < ...
- P1598 垂直柱状图
输入格式: 四行字符,由大写字母组成,每行不超过100个字符 输出格式: 由若干行组成,前几行由空格和星号组成,最后一行则是由空格和字母组成的.在任何一行末尾不要打印不需要的多余空格.不要打印任何空行 ...