zoukankan      html  css  js  c++  java
  • HOJ 3138 Discover's problem

    http://acm.hit.edu.cn/hoj/problem/view?id=3138

    HOJ 3138 Discover's problem

    My Tags 数学   (Edit)
      Source : HCPC FALL 2012
      Time limit : 2 sec   Memory limit : 64 M

    Submitted : 38, Accepted : 13

    We define X property of two array A[n] and B[n] as:
    Write a program to calculate the X property of two array.

    Input

    First line give a number T . Then T cases follows. Each case occupy three lines. The first line is a number n which is the length of arrays. The second and third line each consisting of n positive integers indicate array A[n] and B[n].

    It’s guaranteed that all the integer in the input are not larger than 1000.

    Output

    Print the X property in a line for each input case.

    Sample Input

    3
    1
    2
    2
    2
    1 2
    5 6
    3
    1 2 3
    4 5 6

    Sample Output

    0
    16
    54

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long ll;
    
    const int X = 1005;
    
    ll a[X],b[X];
    ll ans;
    int n;
    
    int main(){
    	freopen("ain.txt","r",stdin);
    	int ncase;
    	cin>>ncase;
    	while(ncase--){
    		cin >> n;
    		ans = 0;
    		ll x = 0,y = 0;
    		for(int i=1;i<=n;i++){
    			scanf("%lld",&a[i]);
    			x += a[i]*a[i];
    		}
    		for(int i=1;i<=n;i++){
    			scanf("%lld",&b[i]);
    			y += b[i]*b[i];
    			ans -= a[i]*b[i];
    		}
    		cout<<-ans*ans+x*y<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    css样式2 布局 定位 层级 显示
    css与样式
    表单属性、键值对
    表单
    列表、表格
    实体、颜色、路径、标签、超链接、图片
    2018/07/05 html基础
    TP 链接数据库与Model模型的创建
    ThinkPHP 模板循环语法
    tp 单字母函数详解(摘自网络)
  • 原文地址:https://www.cnblogs.com/yejinru/p/2862983.html
Copyright © 2011-2022 走看看