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. JSP简单练习-使用JDOM创建xml文件

    注意:在编写代码前,请确保该Web文件夹下的"WEB-INF/lib"下包括jdom.jar包! <%@ page language="java" con ...

  2. Swift - 实现拨打电话

    要实现打电话功能,最简单最直接的方式便是:直接跳到拨号界面 (注意:这个需要真机调试,模拟器无效果) 1 2 //自动打开拨号页面并自动拨打电话 UIApplication.sharedApplica ...

  3. Codeforces Round #112 (Div. 2)---A. Supercentral Point

    Supercentral Point time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. Sencha app build 出现 missing name after . operator 问题

    此问题是在使用sencha app build命令后出现得 主要是 YUI Compressor压缩的时候,代码中出现了delete, interface之类的keyword导致的. 此时能够在Web ...

  5. 研究一下FBrush,它是从TWinControl才有的属性(可能是因为需要句柄)——发现{$R *.dfm}在运行期执行,而且很有深意,读到属性后赋值还会触发事件,这些无法在VCL代码里直接看到

    定义和创建: TWinControl = class(TControl) private FBrush: TBrush; end; constructor TWinControl.Create(AOw ...

  6. 基于visual Studio2013解决面试题之0307最后谁剩下

     题目

  7. cpp check 分析

    1 FileTabCharacterCheck 为什么检查: 因为对于一个TAB而言,所空的空格不定是固定的,如果在机器A上设置了是4个空格,显示正常,而在机器B上阅读,B机器是100个空格为一个TA ...

  8. 找工作笔试面试那些事儿(16)---linux相关知识点(1)

    linux这部分的知识倒不是笔试面试必考的内容,不过现在很多公司开发环境都在linux系统下,一些简单的知识还是需要了解一下的,笔试面试中万一碰到了,也不会措手不及.作为菜硕的我,又因为读研期间的项目 ...

  9. 禁用viewstate

    <asp:Dropdownlist/>禁用viewstate以后 public partial class _Default : System.Web.UI.Page     {      ...

  10. Matlab图像处理系列1———线性变换和直方图均衡

    注:本系列来自于图像处理课程实验,用Matlab实现最主要的图像处理算法 图像点处理是图像处理系列的基础,主要用于让我们熟悉Matlab图像处理的编程环境.灰度线性变换和灰度拉伸是对像素灰度值的变换操 ...