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. window.name 跨域

    跨域的由来 JavaScript出于安全方面的考虑,不允许跨域调用其他页面的对象.但是我们常常会遇到无法避免跨域的情况,如普通文章站点(article.xxx.com)需要评论,而评论站点却在chea ...

  2. 控件风格19种,必须倒背如流——其实就是控件所拥有的能力,即有条件使用VCL框架所提供的(功能)代码

    { New TControlStyles: csNeedsBorderPaint and csParentBackground. These two ControlStyles are only ap ...

  3. Javascript跨域请求的几种解决方法

    什么情况下才会出现跨域? 假设域名是:http://www.example.com.cn/ 如果所请求的域名跟这个域名不致,这种情况就是跨域,由于跨域存在漏洞,所以一般来说正常的跨域请求方式是请求不到 ...

  4. UVA 10718 Bit Mask 贪心+位运算

    题意:给出一个数N,下限L上限U,在[L,U]里面找一个整数,使得N|M最大,且让M最小. 很明显用贪心,用位运算搞了半天,样例过了后还是WA,没考虑清楚... 然后网上翻到了一个人家位运算一句话解决 ...

  5. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  6. 机房收费系统总结之4——VB.NET 轻松解决判断文本框、组合框为空问题

    纵观机房收费系统,判断文本框.组合框为空问题无非两种情况.第一种:判断窗体中所有文本框.组合框是否为空.第二种:判断一部分文本框.组合框是否为空.下面看看是如何实现这两种情况的. 第一种:判断窗体中所 ...

  7. 用log(N)的解法实现数值的整数次方

    // // main.m // c++test // // Created by andyyang on 6/3/13. // Copyright (c) 2013 andyyang. All rig ...

  8. 不容错过的UI设计素材大合集

    免费PSD素材 TETHR by InVision 这是出自InVision的8款PSD文件,其中包含了100个模板和超过500个UI控件.来自InVision和UI8的设计师一同协作完成了这套UI ...

  9. MSSQL - 自增1的标识列一次增长了1000

    @情若天_RunUp: 1. Open "SQL Server Configuration Manager"2. Click "SQL Server Services&q ...

  10. Eclipse ADT 更换主题

    如果Eclipse 版本3.6以上 在 Help→Eclipse Marketplace 搜索 Theme 之后安装即可 如果Eclipse版本3.5 一下, 通过地址安装插件: http://ecl ...