CodeForces 703B Mishka and trip【水题】
来源:互联网 发布:股票量化软件 编辑:程序博客网 时间:2024/06/08 15:53
题意: 一个国家有n个城市,k个首都,城市是一个从1~n~1的一个环,首都通向各个城市。每两个城市间每条路的花费等于两个城市的val的城市,问你遍历所有的路的总花费。
#include <bits/stdc++.h>#define MAXN 100005using namespace std;int main() {int n,m,k,cap[MAXN],c[MAXN] ;bool vis[MAXN];while (scanf("%d%d", &n, &k) != EOF) {__int64 sum = 0; memset(vis, false, sizeof(vis));//用sum记录所有城市的总的魅力值for (int i = 0; i < n; i++) {scanf("%d", &c[i]);sum += c[i];}__int64 ans = c[0]*c[n-1];//在没有首都的情况下for (int i = 0; i < n - 1; i++) {ans += c[i]*c[i + 1];}for (int i = 0; i < k; i++) {scanf("%d", &m);if (m == 1) {//防止两个首都情况if (vis[n]) ans += c[m-1]*c[n-1];if (vis[m + 1]) ans += c[m]*c[m-1];ans += c[m-1]*(sum -c[m-1]-c[m]-c[n-1]);}else if (m == n) {//cout << ans << endl;if (vis[m-1]) ans += c[m-1]*c[m-2];if(vis[1]) ans += c[m-1]*c[0];//cout << ans << endl;ans += c[m-1]*(sum - c[m-1]-c[0]-c[m-2]);}else {if (vis[m-1]) ans += c[m-1]*c[m-2];if(vis[m+1]) ans += c[m-1]*c[m];ans += c[m-1]*(sum - c[m-1]-c[m-2]-c[m]);}vis[m] = true; sum -= c[m-1];//cout<<m<<" "<<sum<<" "<<ans<<endl;}printf("%lld\n", ans);}return 0;}
0 0
- CodeForces 703B Mishka and trip【水题】
- codeforces 703B Mishka and trip
- 【Codeforces 703B - Mishka and trip】
- Codeforces-703B Mishka and trip
- CodeForces 703B Mishka and trip(图论)
- CodeForces 703B Mishka and trip
- CodeForces 703B Mishka and trip
- codeforces 703B. Mishka and trip
- Codeforces 703B Mishka and trip
- codeforces B. Mishka and trip
- 703B - Mishka and trip
- (模拟+数学)codeforces - 703B Mishka and trip
- Codeforces Round #365 (Div. 2) 703B Mishka and trip 水题
- Mishka and trip(CF 703B)
- Coderforces 703B Mishka and trip
- Codeforces Round #365 (Div. 2) B. Mishka and trip
- Codeforces Round #365 (Div. 2) -- B. Mishka and trip
- Codeforces Round #365 (Div. 2) [B] Mishka and trip
- characters
- okhttp3使用
- “除非Microsoft FTP 服务(FTPSVC)正在运行,否则无法启动FTP站点。服务目前已停止”问题解决
- iOS头尾式动画使用
- nrf24l01+
- CodeForces 703B Mishka and trip【水题】
- Gym 100531 D Digits 【暴力】
- Fedora 设置全局 Kindle 护眼色
- CSS背景属性background详解
- recycleview 定义item的 距离的方法。
- 做多选框必备
- c++实现ros by example volume1 例子timed_out_and_back功能
- 一次优化web项目的经历记录(三)
- AngularJS中的定时器,以及定时器的移除