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 ...
随机推荐
- router-link to 动态赋值
路由定义: 动态赋值: <router-link :to="{path:'/old_data_details/params/'+item.id}" > </rou ...
- Codeforces Round #449 [ C/A. Nephren gives a riddle ] [ D/B. Ithea Plays With Chtholly ]
PROBLEM C/A. Nephren gives a riddle 题 http://codeforces.com/contest/896/problem/A codeforces 896a 89 ...
- CSS选择器div和p的用法和区别
div,p.div p.div>p.div+p.div~p.div.a的用法和区别 div,p:选择所有<div>元素和<p>元素 <style> p,spa ...
- JSP页面的Page指令指定编码和Meta标签编码
JSP代码如下: <%@ page language="java" contentType="text/html; charset=UTF-8" page ...
- jmeter常见问题小结
1,报500,查看信息头中的Content-Type 2,https的端口号是443 3,同一个线程组中,不同请求分别用到的字段都可以直接写在‘HTTP信息头管理器’中 4,Debug Sampler ...
- 2019牛客暑期多校训练营(第二场)A 数学
题意 eddy走一个长度为\(n\)的环,每次能往前或往后走一步,问走到\(m\)点恰好走完所有点至少一次的概率,前\(i\)个询问的答案要乘起来 分析 \(n=1,m=0\),答案为\(1\) \( ...
- eclipse打开项目中文件时左侧project explorer同时展开该文件的路径
如图,点击Package Explorer面板上的双向箭头图标即可
- [c++] C++多态(虚函数和虚继承)
转自:https://www.jianshu.com/p/02183498a2c2 面向对象的三大特性是封装.继承和多态.多态是非常重要的一个特性,C++多态基于虚函数和虚继承实现,本文将完整挖掘C+ ...
- sparkOnYarn报错org.apache.hadoop.fs.FSDataInputStream
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInpu ...
- 关于MongoDB在windows下安装【解压版】
一.首先创建数据库存储文件夹和日志文件夹,在mongodb下创建即可,找起来也方便,日志文件:mongo.log,安装出错方便查阅问题: 二.启动MongoDB服务:注意:一定要用管理员身份运行DOS ...