Help Johnny(类似杭电3568题)

Description

Poor Johnny is so busy this term. His tutor threw lots of hard problems to him and demanded him to 
accomplish those problems in a month. What a wicked tutor! After cursing his tutor thousands of times, 
Johnny realized that he must start his work immediately.  
The very problem Johnny should solve firstly is about a strange machine called Warmouth. In the Warmouth 
there are many pairs of balls. Each pair consists of a red ball and a blue ball and each ball is assigned a value. 
We can represent a pair in the form of (R, B) in which R is the value of the red ball and B is of the blue one. 
Warmouth has a generator to calculate the match value of two pairs. The match value of (R1, B1) and (R2, 
B2) is R1*B2+R2*B1. Initially, Warmouth is empty. Pairs are sent into Warmouth in order. Once a new pair 
comes, it will be taken into the generator with all the pairs already in Warmouth.  
Johnny’s work is to tell his tutor the sum of all match values given the list of pairs in order. As the best 
friend of Johnny, would you like to help him? 

Input

The first line of the input is T (no more than 10), which stands for the number of lists Johnny received.  
Each list begins with “N“(without quotes). N is the number of pairs of this list and is no more than 100000. 
The next line gives N pairs in chronological order. The 2i-th number is the value of the red ball of the i-th 
pair and the (2i+1)-th number is the value of the blue ball of the i-th pair. The numbers are positive integers 
and smaller than 100000. 

Output

Please output the result in a single line for each list.

Sample Input

1 3 2 2 3 1 
4 5 6 7

Sample Output

26 58

此题的意思就是给几组数据,按照一定的规则进行运算,要是知道规则很简单的运算。

代码如下:

#include<stdio.h>
#include <iostream>
using namespace std;
int a[100005];
int b[100005];
int main()
{
     long long s1,s2,add;
int n,m,i,j=0;
cin>>n;
for(j=1;j<=n;j++)
{
   add=0,s1=0,s2=0;
cin>>m;
for(i=1;i<=m;i++)
{
cin>>a[i]>>b[i];
s1+=a[i];
s2+=b[i];
}
        for(i=1;i<m;i++)
   {
   s1-=a[i];
   s2-=b[i];
   add+=a[i]*s2+b[i]*s1;
   }
    cout<<add<<endl;
}
return 0;
}

Help Johnny-(类似杭电acm3568题)的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. 杭电oj2093题,Java版

    杭电2093题,Java版 虽然不难但很麻烦. import java.util.ArrayList; import java.util.Collections; import java.util.L ...

  3. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  4. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  5. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  6. 杭电的题,输出格式卡的很严。HDU 1716 排列2

    题很简单,一开始写代码,是用整数的格式写的,怎么跑都不对,就以为算法错了,去看大佬们的算法STL全排列:next_permutation(); 又双叒叕写了好几遍,PE了将近次,直到跑了大佬代码发现, ...

  7. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  8. 杭电21题 Palindrome

    Problem Description A palindrome is a symmetrical string, that is, a string read identically from le ...

  9. 杭电20题 Human Gene Functions

    Problem Description It is well known that a human gene can be considered as a sequence, consisting o ...

随机推荐

  1. 基于W5500+Yeelink的远程灯光控制设计

    概述 工具:物联网云平台Yeelink  DHT11温湿度传感器   W5500EVB 编译环境:Keil4 目的:通过以太网实时监控远程某个位置的温度和湿度 在W5500EVB端连接LED灯.通过W ...

  2. var, object, dynamic的区别以及使用(转载)

    var, object, dynamic的区别以及使用 阅读目录: 一. 为什么是它们三个 二. 能够任意赋值的原因 三. dynamic的用法 四. 使用dynamic的注意事项 拿这三者比较的原因 ...

  3. 基于visual Studio2013解决C语言竞赛题之1058打印数字

       题目 解决代码及点评 /************************************************************************/ /* 58 ...

  4. javascript 如何获取return回来的对象值

    function aa(){ var b = 1; var c = b+2; return{ a1:b, a2:c } } var bb=aa(); alert(bb.a1);

  5. VPS服务器下的centos网卡配置详解……

    自动激活网卡 安装了CENTOS 6.X后,每次启动了系统都需要手动激话网卡,以下方法可以在系统启动后自动激活网卡. cat /etc/sysconfig/network-scripts/ifcfg- ...

  6. 全面解读WM_NOTIFY

    VC中的消息的分类有3种:窗口消息.命令消息和控件通知消息,我们这里要谈的是最后一种:控件通知消息. 控件通知消息,是指这样一种消息,一个窗口内的子控件发生了一些事情,需要通知父窗口.通知消息只适用于 ...

  7. mysql 父子结构排序

    项目中常常会遇到父子结构显示的问题,不同的数据库有不同的写的方式,比方SqlServer中用with union 实现.而Mysql则没有这么方便的语句. 例如以下category表.食品有pizaa ...

  8. Swift - 触摸事件(点击,移动,抬起等)说明及用例

    在iOS开发中,UIGestureRecognizer可以方便的响应处理手势事件. 而如果要想更精细的处理,我们还需要借助touchesBegan,touchesMoved,touchesEnded等 ...

  9. [iOS]简单的APP引导页的实现 (Swift)

    在第一次打开APP或者APP更新后通常用引导页来展示产品特性 我们用NSUserDefaults类来判断程序是不是第一次启动或是否更新,在AppDelegate.swift中加入以下代码: func ...

  10. svn跨机备份

    #!/bin/sh svn_bak_dir='/svndata/cloudil' svn_server='svn://172.16.40.200:9999' user=adminread pass=a ...