Codeforces 703B (模拟) Mishka and trip
题目:这里
题意: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的更多相关文章
- codeforces 703B B. Mishka and trip(数学)
题目链接: B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 703B. Mishka and trip 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #365 (Div. 2) Mishka and trip
Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
- cf703B Mishka and trip
B. Mishka and trip time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 暑假练习赛 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 ...
- CodeForces 703B Mishka and trip
简单题. 先把环上的贡献都计算好.然后再计算每一个$capital$ $city$额外做出的贡献值. 假设$A$城市为$capital$ $city$,那么$A$城市做出的额外贡献:$A$城市左边城市 ...
- CodeForces 703A Mishka and trip
Description Little Mishka is a great traveller and she visited many countries. After thinking about ...
- Codeforces Round #365 (Div. 2) B - Mishka and trip
http://codeforces.com/contest/703/problem/B 题意: 每个点都有一个值,每条边的权值为这两个点相乘.1~n成环.现在有k个城市,城市与其他所有点都相连,计算出 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
随机推荐
- Linux CentOS6.8下解压安装mysql-5.7.14完整介绍
环境:centos6.8 32位本教程安装MySQL是通过编译过的二进制文件进行安装.是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件1.下载 http://dev.m ...
- C#多文档程序中如何只打开一个子窗口
using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; na ...
- location.hash详解
一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如, http://www.example.com/index.html#print 就代表网页index.html的prin ...
- Yaf框架下类的自动加载
前面两篇博客分别讲述了PHP自带的类加载和composer中类的自动加载,其实Yaf框架也实现了基于PSR0和PSR4的类的自动加载.根据我对Yaf下类的自动加载方式的理解写下这篇博客.由于接触Yaf ...
- Orcle学习(一)
exists"和"in"的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ...
- Maven的包依赖冲突可引发java.lang.IncompatibleClassChangeError错误
新版API上线后,发现LOG文件没有正常输出.查看Tomcat的Log文件发现如下的错误信息 May , :: AM com.sun.xml.ws.server.sei.EndpointMethodH ...
- vim的树形菜单NERDTREE的设置
网上比较好的一篇文章:http://coolshell.cn/articles/1679.html http://coolshell.cn/articles/11312.html 1.Vim安装NER ...
- CVPR 2011 Global contrast based salient region detection
Two salient region detection methods are proposed in this paper: HC AND RC HC: Histogram based contr ...
- php curl get
function curlGet($url){ $ch = curl_init(); $header = "Accept-Charset: utf-8"; curl_setopt( ...
- 用sass写栅格系统
为了验证学习sass的效果,自己写了个简单的栅格系统.