题目:这里

题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市

的魅力值的乘积,这n个城市其中还有k个是特殊城市,每个特殊城市和任意一条城市都有一条路连接,看题目下面的图,保证每两个城市之间最多只有一条路,问所有路的

魅力值之和是多少?

首先是连接成环的路线魅力值,很好算,然后每个特殊城市的路线,先求出所有城市的魅力值之和sum,依次求特殊城市的时候用sum减去这个特殊城市本身以及两边相邻的城市

魅力值(因为相邻两边的路已经算过了),再乘这个特殊城市本身魅力值就行,注意这样可能会有路算重复了,而题目显然每条路只能算一次,每次再减去已经出现过的特殊城市

的魅力值之和就行了,注意可能之前出现的特殊城市可能会是现在的特殊城市的左右相邻的城市之一,这样的话就不用减了,因为已经减了,标记一下就行。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long ll;
const int M = 1e5 + ;
ll a[M];bool has[M]; int main()
{
int n,m;
ll sum=,ans=;
scanf("%d%d",&n,&m);
for (int i= ; i<=n ; i++)
{
scanf("%I64d",&a[i]);
if (i>) ans+=(a[i]*a[i-]);
sum+=a[i];
}
ans+=a[]*a[n];
memset(has,false,sizeof(has));
ll cas=;
while (m--)
{
int x,l,r;
scanf("%d",&x);
has[x]=true;
if (x-==) l=n;
else l=x-;
if (x+==n+) r=;
else r=x+;
ans+=(sum-a[x]-a[l]-a[r])*a[x];
ll we=cas;
if (has[l]) we-=a[l];
if (has[r]) we-=a[r];
ans-=we*a[x];
cas+=a[x];
}
printf("%I64d\n",ans);
return ;
}

Codeforces 703B (模拟) Mishka and trip的更多相关文章

  1. codeforces 703B B. Mishka and trip(数学)

    题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. Codeforces 703B. Mishka and trip 模拟

    B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  3. Codeforces Round #365 (Div. 2) Mishka and trip

    Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...

  4. cf703B Mishka and trip

    B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input  standard ...

  5. 暑假练习赛 003 F Mishka and trip

    F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's on ...

  6. CodeForces 703B Mishka and trip

    简单题. 先把环上的贡献都计算好.然后再计算每一个$capital$ $city$额外做出的贡献值. 假设$A$城市为$capital$ $city$,那么$A$城市做出的额外贡献:$A$城市左边城市 ...

  7. CodeForces 703A Mishka and trip

    Description Little Mishka is a great traveller and she visited many countries. After thinking about ...

  8. Codeforces Round #365 (Div. 2) B - Mishka and trip

    http://codeforces.com/contest/703/problem/B 题意: 每个点都有一个值,每条边的权值为这两个点相乘.1~n成环.现在有k个城市,城市与其他所有点都相连,计算出 ...

  9. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

随机推荐

  1. AIDL小结

    AIDL : Android Interface Define Language(接口定义语言) Service中跨进程间通信利器.... 一般都会有Client端和Server端(Server端提供 ...

  2. CString转string

    如题,找了半天... //CString转string USES_CONVERSION; CString temp; temp = _T("kjdsaflkjdlfkj"); ch ...

  3. td的所有style

    td.style.clear= td.style.posRight=0 td.style.backgroundRepeat= td.style.borderTopStyle= td.style.mar ...

  4. opencv嫁接vlfeat densesift

    #include <opencv2/opencv.hpp> #include <iostream> extern "C" { #include <vl ...

  5. How-to: Enable User Authentication and Authorization in Apache HBase

    With the default Apache HBase configuration, everyone is allowed to read from and write to all table ...

  6. Maven本地仓库及远程仓库

    转载自:http://blog.csdn.net/wanghantong/article/details/36427433 Maven 仓库的分类: maven的仓库只有两大类:1.本地仓库 2.远程 ...

  7. SQL Server 索引(index) 和 视图(view) 的简单介绍和操作

    --索引(index)和视图(view)-- --索引(index)----概述: 数据库中的索引类似于书籍的目录,他以指针形式包含了表中一列或几列组合的新顺序,实现表中数据库的逻辑排序.索引创建在数 ...

  8. 【原】如何在jQuery中实现闭包

    原生JS中,闭包虽好用,但是很难用好,在jQuery中一样,都有一些点需要我们注意.jQuery中使用闭包的常见情况有以下几种: 1.$(document).ready()的参数 我们在写jQuery ...

  9. js 和 jq 控制 checkbox

    判断checkbox是否选中  1. $("#id").attr("checked") 在jquery 1.6前(含1.6),返回值是boolean类型的tru ...

  10. LIKE模糊查询的通配符

    LIKE模糊查询的通配符 通配符 说明 示例 % 包含零个或多个字符的任意字符串. WHERE title LIKE '%computer%' 将查找在书名中任意位置包含单词 "comput ...