2018中国大学生程序设计竞赛-网络选拔赛题解
以下所有AC题解程序来自“仙客传奇”团队。
A. Buy and Resell
AC的C++语言程序:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn=1e5+10;
priority_queue< int,vector<int>,greater<int> > buy,sell;
typedef long long ll;
//priority_queue 默认从大到小 修改后从小到大
ll val[maxn];
int main()
{int n,t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lld",&val[i]);ll ans=0,cnt=0;//tiaixao????for(int i=0;i<n;i++){//cout<<ans<<endl;if(buy.size()!=0&&sell.size()!=0&&buy.top()<sell.top()&&sell.top()<val[i]){ans+=val[i];cnt++;sell.push(val[i]);buy.pop();}else if(sell.size()!=0&&sell.top()<val[i]){//交换 buy.push(sell.top());sell.pop();sell.push(val[i]);ans+=val[i]-2*buy.top(); }else if(buy.size()!=0&&buy.top()<val[i]) {ans+=val[i];cnt++;//cout<<i<<endl; sell.push(val[i]);buy.pop();}else buy.push(val[i]),ans-=val[i];}while(buy.size()!=0){ans+=buy.top();buy.pop();}printf("%lld %lld\n",ans,cnt*2);while(!buy.empty()) buy.pop(); while(!sell.empty()) sell.pop();}return 0;
}
/*
4
8
1 2 3 4 5 6 7 8
4
1 2 10 9
5
9 5 9 10 5
2
2 1*/
B. Congruence equation
题解链接:
HDU 6439 Congruence equation(莫比乌斯反演)
HDU 6439 2018CCPC网络赛 Congruence equationI(杜教筛 + 莫比乌斯反演 + 伯努利数)
C. Dream
题解链接:
2018中国大学生程序设计竞赛 - 网络选拔赛(hdu6440 Dream)
D. Find Integer
AC的C++语言程序:
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 4e4;int main()
{// ios::sync_with_stdio(false);
// cin.tie(NULL);cout.tie(NULL);int T,n,a;scanf("%d",&T);while(T--){scanf("%d%d",&n,&a);if(n == 0 || n > 2) printf("-1 -1\n");else if(n == 1)printf("1 %d\n",a + 1);else if(n == 2){if(a % 2 == 0)printf("%d %d\n",a * a / 4 - 1, a * a / 4 + 1);elseprintf("%d %d\n",(a - 1) * (a / 2 + 1),(a - 1) * (a / 2 + 1) + 1); } }return 0;
}
E. GuGu Convolution
题解链接:
HDU 6442 GuGu Convolution(快速幂)
hdu 6442 - 二项式定理
F. Neko and Inu
G. Neko’s loop
题解链接:
hdu6444(最大子段和+gcd)
hdu 6444 - 最大子段和(单调队列)
H. Search for Answer
题解链接:
HDU 6445(竞赛图 + 网络流)
HDU 6445 2018CCPC网络赛1008 Search for Answer(费用流 + 构图)
I. Tree and Permutation
AC的C++语言程序:
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
const int mod = 1e9 + 7;ll fac[maxn + 10],n,sum;struct edge
{int u,v;ll w;edge(){}edge(int _u,int _v,ll _w):u(_u),v(_v),w(_w){}
}e[maxn + 10];
vector<edge> son[maxn + 10];
int cnt[maxn + 10],vis[maxn + 10];
ll fa[maxn + 10];void getfac()
{fac[0] = fac[1] = 1;for(int i = 2;i <= maxn;++i)fac[i] = (fac[i - 1] * i) % mod;
}int dfs(int no)
{int cnt = 1;vis[no] = 1;for(int i = 0;i < son[no].size();++i)if(!vis[son[no][i].v]) {int temp = dfs(son[no][i].v);cnt += temp;sum = (sum + ((son[no][i].w * fac[n - 1] * 2ll) % mod * ((n - temp) * temp) % mod)) % mod;}return cnt;
}int main()
{ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);getfac();while(cin>>n){// memset(cnt,0,sizeof(cnt));memset(vis,0,sizeof(vis));for(int i = 1;i <= n;++i) son[i].clear();for(int i = 1;i < n;++i){int u,v,w;cin>>u>>v>>w;son[u].push_back(edge(u,v,w));son[v].push_back(edge(v,u,w));}sum = 0;dfs(1); cout<<sum<<endl;}return 0;
}
AC的C++语言程序:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define INF 2147483647
#define MEM(x, b) memset(x, b ,sizeof(x))
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 2;
int n;
vector<pair<int, int> > edge[MAXN];
int num[MAXN];
ll fac[MAXN];
ll ans;
void dfs(int crt, int fa){for (int i = 0; i < edge[crt].size(); i++) {int u = edge[crt][i].first; if (u == fa) continue;dfs(u, crt);num[crt] += num[u];ans =(ans + 1ll*(num[u]) %MOD * (n - num[u]) % MOD* fac[n - 1] % MOD * 2ll % MOD * edge[crt][i].second % MOD) % MOD;}
}int main() {fac[0] = 1;for (int i = 1; i < MAXN; i++) {fac[i] = (fac[i - 1] * (long long)i % MOD) % MOD;}while (~scanf("%d", &n)){ans = 0;for (int i = 1; i <= n; i++) edge[i].clear();//MEM(num, 1);for (int i = 1; i<= n; i++) num[i] = 1; for (int i = 1; i < n; i++){int u , v, w;scanf("%d%d%d",&u,&v,&w);edge[u].push_back(make_pair(v, w));edge[v].push_back(make_pair(u, w));}//cout << "ds" << endl;dfs(1, 0);printf("%lld\n", ans);}return 0;
}
J. YJJ’s Salesman
AC的C++语言程序:
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 2;struct node{int x, y, w;bool operator < (node A) {if (x == A.x) {return y>A.y;}else return x < A.x;}
};node p[MAXN];
int tr[MAXN], a[MAXN];
int n ,tot;
int lowbit(int x){return (x & (-x));
}int query(int l) {int maxn = 0;for (int i = l; i >=1; i-=lowbit(i)){maxn = max(maxn, tr[i]);}return maxn;
}void add(int pos , int val) {tr[pos]= val;for (int i = pos; i <= MAXN; i+= lowbit(i) ){tr[i] = max(tr[i], val);}
}int main() {int t;scanf("%d", &t);while (t--) {memset(tr, 0 ,sizeof(tr));scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].w);a[i] = p[i].y;}sort(a , a + n);tot = unique(a, a + n) - a;for (int i = 0; i < n; i++){p[i].y = lower_bound(a, a + n, p[i].y) - a + 1;}sort(p, p + n);for (int i = 0; i < n; i++){int val = query(p[i].y - 1) + p[i].w;add(p[i].y, val);}printf("%d\n", query(MAXN - 1)) ;}}
题解链接:
BEIL 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 Goldbach
ACDIJ 2018中国大学生程序设计竞赛网络选拔赛
2018中国大学生程序设计竞赛-网络选拔赛题解相关推荐
- Buy and Resell 2018中国大学生程序设计竞赛 - 网络选拔赛
题目 题意: n个宝石,宝石的买入或卖出价格固定,一天只能到一个珠宝商店(从左到右),问最大利润是多少?在保证最大利润的同时最少交换次数是多少? 题解: 题目有两问:一个是求利润,一个是求次数 利润就 ...
- 2018中国大学生程序设计竞赛 – 网络选拔赛 1001 Buy and Resell [模拟]
1001 Buy and Resell 题目:有1-n个货物,可以在某个点buy,然后在后面的点resell,可以同时买多个,问最大的利润和最小的交易次数. 题解:模拟运算,前 i 天都是可以买的, ...
- 2018中国大学生程序设计竞赛 - 网络选拔赛
传送门 A.HDU6438 Buy and Resell 题意 给你N天N个价格,每天都可以从1.买入一个,2.卖出一个,3.什么都不做,求最高获利 低买高卖问题,这题与其他的差距就是要在满足获利最多 ...
- 字节跳动杯2018中国大学生程序设计竞赛-女生专场题解
以下所有AC题解程序来自"仙客传奇"团队. A. 口算训练 题解链接: ABDFHK "字节跳动杯"2018中国大学生程序设计竞赛-女生专场 B. 缺失的数据范 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 [1005 - CaoHaha's staff] 贪心
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1005&cid=779 题目大意:在一个二维坐标网格里画线,可 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 [1003 - Friend-Grapht] 图论
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1003&cid=779 题目大意:给一个团队的关系图,问这个团 ...
- 挑战程序设计竞赛_我系首次参加第六届中国大学生程序设计竞赛网络预选赛
点击上方蓝字关注 「龙外信息工程系」 讲述有温度的故事 传递有态度的思想 2020年9月20日12时至17时,第六届中国大学生程序设计竞赛网络赛预选赛在杭州电子科技大学OJ成功举办,黑龙江外国 ...
- 字节跳动杯2018中国大学生程序设计竞赛-女生专场
(6/11)施工施工... A.口算训练 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6287 题解给的根号的分解素因子,其实能够做到log,然后维护 ...
- “字节跳动杯“2018中国大学生程序设计竞赛-女生专场
A-口算训练 题目大意 判断区间[l,r]内的数组元素乘积是否为d的倍数 思路:分解质因数+二分(upper_bound.lower_bound) ==>若区间[l,r]中所有数的每一个质因数的 ...
最新文章
- 《MSSQL2008技术内幕:T-SQL语言基础》读书笔记(下)
- 从Dart列表中删除重复项的2种方法
- 【Transformer】Are Transformers More Robust Than CNNs?
- maven 构建 springmvc + spring security 权限控制示例
- 雷赛运动控制卡能不能用c语言_弱电知识之三:跟我学做全彩屏,认识LED全彩屏的模组、控制卡...
- cmake vscode 高亮_vscode中cmake项目管理和调试
- ionic3.0--angular4.0 引入第三方插件库的方法
- 要想成功必须具备的九种手段
- 最新版网站推广完全手册(2007年)!
- 哪种软件测试硬盘速度,哪种工具最适合硬盘,SSD,U盘,存储卡速度性能测试?...
- 【Android】面试宝典
- python_lintcode_52翻转字符串_128哈希函数
- 【微信小程序】关于getCurrentPages()的使用
- 云计算考证笔记、CPU虚拟化、内存虚拟化、IO虚拟化、存储虚拟化
- MeterSphere开发者手册
- html 导航切换内容
- 处理器压力测试软件,处理器压力测试小工具——云汉烤机大师
- 计算机专业去支教学到什么,支教的收获及感悟4篇_大学生支教感想
- 【BZOJ1064】[Noi2008]假面舞会 DFS树
- 大数据技术之DataX (一)DataX插件开发
热门文章
- 简书首页标题配图bug,偶发,未能重现(可以重现2017-12)
- VSCode插件开发全攻略
- BoltDB 一个简单的纯 Go key/value 存储 [译]
- 三、Nginx内置变量
- 每天Leetcode 刷题 初级算法篇-有效的括号
- Bug--Tomcat Error start child
- hive 外部表不支持添加列
- Kafka的介绍之一
- 洛谷P1127 词链 欧拉路问题
- TensorFlow基础篇(八)——tf.contrib.layers.l1regularizer()-12_regularizer(lambda)