st

F. Maximum Weight Subset

时光毁灭记忆、已成空白 提交于 2019-12-02 03:20:13
题意:给一颗树,边权为1,节点有点权,问取到一个点集,俩俩之间路径超过k,是点权和最大 思路:贪心地取点,先将点按照深度经行排序,每一次,取一个点权大于0的点,然后对于这个点bfs出去的路径小于k的点减去当前点的a[u],然后将a[i]加入到ans中 #include<bits/stdc++.h> using namespace std; #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=b;i>=a;i--) #define pb push_back const int M=250; int deep[M],vis[M],a[M],b[M],k,n; vector<int>g[M]; void dfs(int u,int f){ deep[u]=deep[f]+1; for(int i=0;i<g[u].size();i++){ int v=g[u][i]; if(v!=f){ dfs(v,u); } } } bool cmp(int x,int y){ return deep[x]>deep[y]; } struct node{ int val,st; }; int bfs(int st){ queue<node>que; node s; s.val=st; s.st=0; que.push

快排---非递归实现

牧云@^-^@ 提交于 2019-12-02 01:48:29
递归的核心是栈;可构造辅助栈实现非递归。 #include<iostream> #include <stdio.h> #include <stack> using namespace std; int partion(int* root, int low, int high) { int part = root[low]; while(low < high) { while(low<high && root[high]>part){ high--; } root[low] = root[high]; while(low<high && root[low]<=part) { low++; } root[high] = root[low]; } root[low] = part; return low; } void quickSort2(int* root, int low, int high) { stack<int> st; int k; if(low < high) { st.push(low); st.push(high); while(!st.empty()) { int j = st.top(); st.pop(); int i = st.top(); st.pop(); k = partion(root, i, j); if(i < k - 1) { st.push(i

【提高组】强连通分量

最后都变了- 提交于 2019-12-02 00:15:23
P2746 [USACO5.3]校园网Network of Schools 翻译题面: 任务A:求缩点后的图中有多少个点入度为0。 任务B:求入度为0的点数与出度为0的点数的较大值。 注意避免连边时重复算出度入度,所以用set而非vector存图;只有一个点(缩点后)要 特判 。 写代码时注意定义 For 的话不能写成 For(j,0,g[i].size()-1), 查了至少30min... #include <bits/stdc++.h> #define ri register int #define For(i,l,r) for(ri i=l;i<=r;i++) using namespace std; const int M=105; vector<int> g[M]; stack<int> st; set<int> gg[M]; int n,dfn[M],low[M],inst[M],belong[M],in,cnt,indg[M]; inline void tarjan(int x){ low[x]=dfn[x]=++in;st.push(x);inst[x]=1; //For(i,0,g[x].size()-1){ for(int i=0;i<g[x].size();i++){ if(!dfn[g[x][i]]) tarjan(g[x][i]),low[x]=min

洛谷P1583 魔法照片

我怕爱的太早我们不能终老 提交于 2019-12-01 20:11:12
https://www.luogu.org/problem/P1583 话不多说,其实就是模拟,然后,各种繁琐 #include<bits/stdc++.h> using namespace std; struct st { int bianhao; int w; int d; int c; int zong; } stu[20005]; bool cmp1(st a,st b) { if(a.w==b.w) return a.bianhao<b.bianhao; return a.w>b.w; } bool cmp2(st a,st b) { if(a.zong==b.zong) return a.bianhao<b.bianhao; return a.zong>b.zong; } int main() { int n,k; cin>>n>>k; int E[11],W[20005]; for(int i=1; i<=10; i++) cin>>E[i]; for(int i=1; i<=n; i++) cin>>W[i]; for(int i=1; i<=n; i++) { stu[i].bianhao=i; stu[i].w=W[i]; } sort(stu+1,stu+1+n,cmp1); for(int i=1; i<=n; i++) { stu[i].d=i; stu

luoguP2466 [SDOI2008]Sue的小球

孤街浪徒 提交于 2019-12-01 20:03:51
此题与 \(luoguP1220\) 关路灯类似,但是这个题目的收益随时间的变化而变化. 起初我思考来一个三维 \(dp\) ,即两维坐标,一维时间. 可惜爆了空间(艹). 但是由于时间是线性的,所以我们可以反着设. 即设 \(dp[0/1][st][ed]\) 表示处理完按坐标排序后的第 \(st\) 个蛋到第 \(ed\) 个蛋被处理完后对于剩下的蛋所产生的影响. 答案即为 \(\sum^{n}_{i=1}y[i]-\min(dp[0][1][n],dp[1][1][n])\) . 转移即为普通的区间 \(dp\) 套路. \[ \begin{align} dp[0][st][ed]=&min(dp[0][st][ed],min(\\&dp[0][st+1][ed]+(sum[n]+sum[st]-sum[ed])*(a[st + 1].x - a[st].x),\\&dp[1][st + 1][ed] + (sum[n] + sum[st] - sum[ed]) * (a[ed].x - a[st].x)));\\ dp[1][st][ed]=&min(dp[1][st][ed],min(\\&dp[1][st][ed - 1] + (sum[n] + sum[st - 1] - sum[ed - 1]) * (a[ed].x - a[ed - 1].x),\\&dp[0]

POJ - 1062 - 昂贵的聘礼 = Dijkstra

匆匆过客 提交于 2019-12-01 19:47:05
http://poj.org/problem?id=1062 题意:有100个物品,每个物品有一个价格值,一个地位值,和他可以用别的物品来补差价换。求换到1号物品的最小代价。 意思就是给一个图,支付起点的点权,然后走边权走到1号点,求最小的代价,其中路上经过的地位值的差不能超过题目的限制。 最暴力的做法,枚举地位的差,每次在反图上跑一次Dijkstra就好。这样貌似进行了多余的拷贝。 #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<map> #include<set> #include<stack> #include<string> #include<queue> #include<vector> using namespace std; typedef long long ll; vector<pair<int, int> >G0[105]; vector<pair<int, int> >G[105]; struct Item { int id; int st; int val; } item[105]; int dis[105]; bool vis[105]; priority_queue<pair<int, int> > pq;

ccf-201909-4

≯℡__Kan透↙ 提交于 2019-12-01 16:40:36
中等的模拟题,自己写的太搓了。 自己原来写了离散化,后来删了 原来超时,后来加了一个很小的优化 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #include<set> #include<bitset> #include<unordered_map> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; #define pb(x) push_back(x) #define cls(x, val) memset(x, val, sizeof(x)) #define fi first #define se second #define mp(x, y) make_pair(x, y) #define inc(i, l, r) for(int i=l; i<=r; i++) const int inf = 0x3f3f3f3f; const int maxn = 3e5+10; int a[maxn]; int

Educational Codeforces Round 74 (Rated for Div. 2) B. Kill 'Em All

你说的曾经没有我的故事 提交于 2019-12-01 12:35:11
链接: https://codeforces.com/contest/1238/problem/B 题意: Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters. The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let's assume that the point x=0 is where these parts meet. The right part of the corridor is filled with n monsters — for each monster, its initial coordinate xi is given (and since all monsters are in the right part, every xi is

软工第四次作业

萝らか妹 提交于 2019-12-01 10:38:58
软工第四次作业 GIT地址 https://github.com/xzx63321/WordCount 结对伙伴 向天强 伙伴学号 201831061328 伙伴博客地址 https://www.cnblogs.com/a1290389465/ 一、PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 15 30 · Estimate · 估计这个任务需要多少时间 2595 1800 Development 开发 1300 1400 · Analysis · 需求分析 (包括学习新技术) 60 80 · Design Spec · 生成设计文档 60 90 · Design Review · 设计复审 (和同事审核设计文档) 40 40 · Coding Standard · 代码规范 (为目前的开发制定合适的规范) 30 30 · Design · 具体设计 100 130 · Coding · 具体编码 630 750 · Code Review · 代码复审 40 60 · Test · 测试(自我测试,修改代码,提交修改) 120 140 Reporting 报告 90 90 · Test Report · 测试报告 40 60 · Size Measurement ·

软件第四次作业

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 10:35:49
软工第四次作业 GIT地址 https://github.com/xzx63321/WordCount 结对伙伴 肖子轩 伙伴学号 201831061329 伙伴博客地址 https://www.cnblogs.com/xzx23361/ 一、PSP表格 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 15 30 · Estimate · 估计这个任务需要多少时间 2595 1800 Development 开发 1300 1400 · Analysis · 需求分析 (包括学习新技术) 60 80 · Design Spec · 生成设计文档 60 90 · Design Review · 设计复审 (和同事审核设计文档) 40 40 · Coding Standard · 代码规范 (为目前的开发制定合适的规范) 30 30 · Design · 具体设计 100 130 · Coding · 具体编码 630 750 · Code Review · 代码复审 40 60 · Test · 测试(自我测试,修改代码,提交修改) 120 140 Reporting 报告 90 90 · Test Report · 测试报告 40 60 · Size Measurement · 计算工作量