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 ...
随机推荐
- ES head
第2种安装方式 第二种方式就是不通过Elasticsearch插件方式进行安装 1.下载elasticsearch-head的源码包 地址:https://github.com/mobz/elasti ...
- New!Devexpress WinForms各版本支持Visual Studo和SQL Server版本对应图
点击获取DevExpress v19.2.3最新完整版试用下载 本文主要为大家介绍DevExpress WinForms各大版本支持的VS版本和支持的.Net版本图,Devexpress WinFor ...
- php+memcache实现的网站在线人数统计
<?php $mc = new Memcache (); // 连接memcache $mc->connect ( ); // 获取 在线用户 IP 和 在线时间数据 $online_me ...
- __slots__节约空间
1.为什么要使用__slots__ Python 使用 dicts(hash table)缓存大量的静态资源(属性). 我们最近在Image类中,用仅仅一行__slots__代码,改变成使用tuple ...
- Flyway的简单介绍和使用(转)
Flyway的简单介绍及使用 一.开发时管理数据库遇到的问题: 现在开发一般都是团队开发,这样就会出现项目同步的问题,代码同步可以通过SVN工具管理起来,那数据库同步怎么办呢?理想的情况下,在开发新项 ...
- ipvsadm命令用法
ipvsadm命令选项 -A 添加虚拟服务器 -E 修改虚拟服务器 -D ...
- 使用nodejs进行开发,concurrently模块,使我们同时执行多个命令。
concurrently模块使用. 安装模块 npm install concurrently 配置concurrently 运行多个服务 当我们使用nodejs和vue混合开发的时候.当要同时启动后 ...
- js的三种异步处理
js的三种异步处理 Promise 对象 含义: Promise是异步编程的一种解决方案, 优点: 相比传统回调函数和事件更加合理和优雅,Promise是链式编程(后面会详细讲述),有效的解决了令 ...
- 改变CTS测试中timeout时间
关键类: JarHostTest.java——>目录:%SOURCE_ROOT%/cts/tools/tradefed-host/src/com/android/cts/tradefed/tes ...
- HYSBZ - 3813 奇数国 欧拉函数+树状数组(线段树)
HYSBZ - 3813奇数国 中文题,巨苟题,巨无敌苟!!首先是关于不相冲数,也就是互质数的处理,欧拉函数是可以求出互质数,但是这里的product非常大,最小都2100000,这是不可能实现的.所 ...