A. Integer Points

第二天叫醒我的不是闹钟,是梦想!

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), 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≤105), the number of lines drawn by DLS.

The second line of a test case contains n distinct integers pi (0≤pi≤109) describing the lines drawn by DLS. The integer pi describes a line given by the equation y=x+pi.

The third line of a test case contains an integer m (1≤m≤105), the number of lines drawn by JLS.

The fourth line of a test case contains m distinct integers qi (0≤qi≤109) describing the lines drawn by JLS. The integer qi describes a line given by the equation 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
inputCopy

3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1
outputCopy
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.

//y=x+pi,y=-x+qi.例如:y=x+1,y=-x+3 那么2y=4 也就是说pi+qi必须是2的倍数才会相交。也就是偶数,我们可以预处理b数组有多少个奇数和多少个个数。根据奇数+奇数=偶,偶+偶=偶这个性质求解即可


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int t;
int n,m;
int a[N],b[N],x;
int main()
{
    cin>>t;
    while(t--)
    {
      cin>>n;
      for(int i=1;i<=n;i++) cin>>a[i];
      int l=0,r=0;
      cin>>m;
      for(int i=1;i<=m;i++)
      {
        cin>>x;
        if(x%2==0) l++;
        else r++;
      }
      ll res=0;
      for(int i=1;i<=n;i++)
      {
        if(a[i]%2==0) res+=l;
        else res+=r;
      }
      cout<<res<<endl;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我根据以下要求:Add to the Model class a new method called savaData that saves into a text file called "points.txt" the integer coordinates x and y of each point in the arraylist of points. Also modify the constructor of the Model class to read the integer coordinates of all the points from the same text file, if it exists, and put them into the arraylist of points (if the file does not exist then the arraylist of points should remain empty).public class Model { private ArrayList<Point> points; private ArrayList<ModelListener> listeners; public Model() { points = new ArrayList<Point>(); listeners = new ArrayList<ModelListener>(); } public void addListener(ModelListener l) { listeners.add(l); } public ArrayList<Point> getPoints() { return points; } public void addPoint(Point p) { points.add(p); notifyListeners(); // points changed so notify the listeners. } public void clearAllPoints() { points.clear(); notifyListeners(); // points changed so notify the listeners. } public void deleteLastPoint() { if(points.size() > 0) { points.remove(points.size() - 1); notifyListeners(); // points changed so notify the listeners. } } private void notifyListeners() { for(ModelListener l: listeners) { l.update(); // Tell the listener that something changed. } } public int numberOfPoints() { return points.size(); } public static void testModel() { Model m = new Model(); m.addListener(new ModelListener() { @Override public void update() { System.out.println(true + " (listener)"); } }); System.out.println(m.getPoints() == m.points); Point p1 = new Point(1, 2); Point p2 = new Point(3, 4); m.addPoint(p1); // Listener called. m.addPoint(p2); // Listener called. System.out.println(m.numberOfPoints() == 2); System.out.println(m.points.get(0) == p1); System.out.println(m.points.get(1) == p2); m.deleteLastPoint(); // Listener called. System.out.println(m.numberOfPoints() == 1); System.out.println(m.points.get(0) == p1); m.clearAllPoints(); // Listener called. System.out.println(m.numberOfPoints() == 0); m.notifyListeners(); // Listener called. } }修改下述代码:
05-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值