Codeforces703B Mishka and trip
题意:
就是有n个点,本来相邻点之间就有一条边,1和n之间也有一条,然后给你几个特殊点,说这些特殊点和其他所有点都连起来了,然后算一个所有边的权值和,每条边的权值等于两个点的c相乘。
思路:
水题啊…感觉有好多方法吧。弱的思路:你把所有点都相连的情况,把所有边权值和算出来,然后没有被标记的点拿出来,把他们两两相连的边的权值也减掉,但是你会发现就算没有标记但是相邻还是会有边,所以加上这些就好了。
比赛时的挫code…………..
#include<cstdio>
#include<math.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int N=1e5+10;
LL v1[N];
LL v2[N];
bool vis[N];
LL sum[N];
LL s2[N];
int main()
{
int n,k,x;
scanf("%d%d",&n,&k);
memset(vis,0,sizeof(vis));
memset(sum,0,sizeof(sum));
memset(s2,0,sizeof(s2));
for(int i=1;i<=n;i++)
{
scanf("%d",&v1[i]);
sum[i]=sum[i-1]+v1[i];
}
LL ans1=0,ans2=0,ans3=0;
for(int i=1;i<=n;i++)
ans1+=v1[i]*(sum[i-1]); //刚刚好 ,全部相连
for(int i=1;i<=k;i++)
{
scanf("%d",&x);
vis[x]=1;
}
int num=1;
for(int i=1;i<=n;i++)
{
if(i==n)
{
if(!vis[i])
{
if(vis[i]==vis[1])
ans2+=v1[1]*v1[n];
v2[num]=v1[i];
s2[num]=s2[num-1]+v2[num];
++num;
}
}
else{
if(!vis[i])
{
if(vis[i]==vis[i+1])
ans2+=v1[i]*v1[i+1];
v2[num]=v1[i];
s2[num]=s2[num-1]+v2[num];
++num;
}
}
}
for(int i=1;i<=num;i++)
ans3+=v2[i]*s2[i-1];
// printf("%I64d %I64d %I64d\n",ans1,ans2,ans3);
printf("%I64d\n",ans1+ans2-ans3);
}
Codeforces703B Mishka and trip的更多相关文章
- 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 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- 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 703A Mishka and trip
Description Little Mishka is a great traveller and she visited many countries. After thinking about ...
- B. Mishka and trip
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- cf B. Mishka and trip (数学)
题意 Mishka想要去一个国家旅行,这个国家共有个城市,城市通过道路形成一个环,即第i个城市和第个城市之间有一条道路,此外城市和之间有一条道路.这个城市中有个首中心城市,中心城市与每个城市(除了 ...
- Codeforces 703B (模拟) Mishka and trip
题目:这里 题意:n个城市,每个城市有个魅力值vi,首先,有n条路将这n个城市连成一个环,1号城市连2号城市,2号连3号****n号连1号城市,每条路的魅力值是其连接的两个城市 的魅力值的乘积,这n个 ...
随机推荐
- window7_64安装STAF
1. 安装包下载 从http://sourceforge.net/projects/staf/files/staf/V3.4.17/下载所需安装包,有Windows.Linux.Solar ...
- stream_context_create()模拟POST/GET
有时候,我们需要在服务器端模拟 POST/GET 等请求,也就是在 PHP 程序中去实现模拟,该怎么做到呢?或者说,在 PHP 程序里,给你一个数组,如何将这个数组 POST/GET 到另外一个地址呢 ...
- hihoCoder 1234 fractal
#1234 : Fractal 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specific ...
- 使用mysql导入数据时关掉binlog
在my.cnf中注释掉 log-bin=bin-log参数然后重启数据库
- UltraEdit中使用正则表达式-简单用法
UltraEdit中使用正则表达式 1.认识正则表达式语法: 正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串 ...
- Android Baseline小tip
转载请注明出处:http://blog.csdn.net/bbld_/article/details/40709353 Baseline Alignment
- 【POJ 1159】Palindrome
[POJ 1159]Palindrome 近期各种题各种奇葩思路已经司空见惯了...又新出个滚动数组= = 该题另一点须要知道 最少须要补充的字母数 = 原序列S的长度 - S和S'的最长公共子串长度 ...
- 谈谈Paxos一致性算法和一致性这个名词
转自:http://www.cnblogs.com/esingchan/p/3917718.html 维基的简介:Paxos算法是莱斯利·兰伯特(Leslie Lamport,就是 LaTeX 中的& ...
- HDU 2222 Keywords Search(瞎搞)
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- 大整数分解质因数(Pollard rho算法)
#include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> ...