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. 多屏广告技术调研 & 广告基础介绍

    之前做的多屏广告产品调研,并简单介绍了一些基础广告知识.见ppt:多屏广告技术调研

  2. Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)

    1.当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(Vie ...

  3. mfc对话框不能响应键盘消息

    这东西真是奇怪,找了半天原因,最终的发现却是让人抓狂,呵呵 现象:对话框按ESC或回车都不能关闭窗口(我没有处理PreTransplanteMessage),用spy++看,对话框完全收不到键盘消息 ...

  4. Swift - 将String类型的数字转换成数字类型

    Swift中,如果要把字符串转换成数字类型(比如整型,浮点型等).可以先转成NSString类型,让后再转. 1 2 3 4 //将文本框中的值转换成数字 var i = (tf1.text as N ...

  5. Tomcat启动会遇到的问题部分解决方案

    Tomcat的启动不一定会非常的顺利,这可以有多种原因 一.Tomcat是由Java所编写的,因此Tomcat的使用需要JDK的支持,如果没有配置环境变量,Tomcat当然无法启动,最明显的特征就是点 ...

  6. 做SEO推广必须要做的9件事儿

    SEO推广是由网站优化网络运营媒体宣传结合的一种技术,而现在恰好就是媒体最为流行,真因为如此很多的站长之知道利用自媒体推广网站,结果推广了几年网站权重只有2到3而已,导致和谐问题的关键就是没有结合其他 ...

  7. 与众不同 windows phone (5) - Chooser(选择器)

    原文:与众不同 windows phone (5) - Chooser(选择器) [索引页][源码下载] 与众不同 windows phone (5) - Chooser(选择器) 作者:webabc ...

  8. 枚举算法总结 coming~^.*

    感谢CJ同学监督╭(╯^╰)╮.从放假到现在都木有更新博客了~噶呜~小娘谨记教诲,每天会更新博客==!! 看了一下POJ训练计划,虽然已经零零散散做了40多道题了,还是从头开始整理一下漏掉的知识点.T ...

  9. Sql Server中COUNT(字段名)跟COUNT(*)的特殊不同点

    今天有个需求,有2张表: 1.一个“搜索记录”表search,一个“搜索后下载记录”表down 2.映射关系:每一个下载记录对应一条搜索记录,                           第个 ...

  10. hdu1392 Surround the Trees 凸包

    第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...