- 博客(187)
- 收藏
- 关注
原创 Codeforces
http://codeforces.com/contest/664/problem/A给定整数 a,b,求 gcd(a,a + 1,··· ,b)1 ≤ a ≤ b ≤ 10^100因为连续的两个自然数是互质的#include<cstring>#include<iostream>using namespace std;string s,s1;in...
2019-02-28 15:05:07 235 1
原创 vjudge
https://vjudge.net/problem/HihoCoder-1121#include<cstdio>#include<cstring>#include<vector>#include<iostream>#define N 10000010using namespace std;vector<int>E[N]...
2019-02-25 22:13:52 2352
原创 noip铺地毯
https://www.luogu.org/problemnew/show/P1003 #include <iostream>#include<cstdio>using namespace std;int n,a[10003][5],i,j,i1;int main(){ scanf("%d",&n); for (i=1; i<=...
2019-02-25 20:36:31 189
原创 poj
http://poj.org/problem?id=2239#include<cstdio>#include<cstring>#define N 1000using namespace std;int a[N][N],w,c,v[N],t,iswho[N],i,j,n,m,ans;int dfs(int x){ for (int i=1;i<=7*1...
2019-02-25 20:25:08 102
原创 hdu
http://acm.hdu.edu.cn/showproblem.php?pid=3549 #include<cstdio>#include<cstring>#include<iostream>#include<queue>#define M 30000#define N 10000#define INF 100000000...
2019-02-25 11:21:16 128
原创 挑战程序设计3
二分答案bool C(double x){ int num=0; for (i=0; i<n; i++) num+=l[i]/x; return num>=k}l=0;r=INF;for (i=0; i<=100; i++){ double mid=(l+r)/2; if (C(mid)) ...
2019-02-23 21:49:40 190
原创 贪心和高精度
分数背包(部分背包):有一个容量为 V 的背包和若干物品,物品有重量和价值。假设物品可以被无限细分,且细分后价值重量比不变。求可以装下的最大价值。 假设物品可以被无限细分,且细分后价值重量比不变。贪心的做法:优先装性价比高的物品,直到这种物品用完或背包装满01 背包:有一个容量为 V 的背包和若干物品,物品有重量和价值。物品不能被分割。求可以装下的最大价值。贪心的做法...
2019-02-23 20:47:01 6405 20
原创 基本套路选讲
https://www.luogu.org/problemnew/show/P1008https://www.luogu.org/problemnew/show/P2668这道题明显就是一个大暴力,但是考场上碰到这种题确实让人伤脑筋,如何在考场上稳稳地拿下这100分呢?首先,为了进行完全的搜索,这题应用DFS的结构,而不是贪心选择某种出牌方式。然后我们应先分析搜索的方法。在DFS...
2019-02-23 20:43:35 85
原创 挑战程序设计竞赛2
bool dfs(int v,int c){ color[v]=c; for (int i=0; i<G[v].size(); i++) if (color[G[v][i]]==c) return 0; if (color[G[v][i]]==0&& !dfs(G[v][i],-c)) ...
2019-02-23 18:36:30 323
原创 挑战程序设计竞赛1
1.抽签你的朋友提议玩一个游戏:将写有数字的 n 个纸片放入口袋中,你可以从口袋中抽取 4 次纸片,每次记下纸片上的数字后都将其放回口袋中.如果这 4 个数字的和是 m,就是你赢,否则就是你的朋友赢.请你编写一个程序,判断当纸片上所写的数字是 k1, k2,...., kn时,是否存在抽取 4 次和为 m 的方案。如果存在,输出 Yes;否则,输出 No. 1 ≤ m ≤ 10^81...
2019-02-23 15:12:56 637
原创 信息传递
http://icpc.upc.edu.cn/problem.php?cid=1689&pid=1#include<cstdio>#include<iostream>using namespace std;int f[20000010],a,d[2000010],i,j,k,ans=1000000000,n;int find(int x){ ...
2019-02-23 14:47:26 142
原创 推销员
http://icpc.upc.edu.cn/problem.php?cid=1688&pid=3X=1:向住户5推销,往返走路的疲劳值为5+5,推销的疲劳值为5,总疲劳值为15。X=2:向住户4、5推销,往返走路的疲劳值为5+5,推销的疲劳值为4+5,总疲劳值为5+5+4+5=19。X=3:向住户3、4、5推销,往返走路的疲劳值为5+5,推销的疲劳值3+4+5,总疲劳值为5...
2019-02-22 15:35:05 161
转载 数据结构
文章目录一, 线性数据结构栈:(stack)队列: (queue)并查集:Hash:二、树形数据结构[树状数组](https://blog.csdn.net/weixin_43464026/article/details/83420305)线段树二叉搜索树存储结构遍历:查找一, 线性数据结构栈:(stac...
2019-02-22 09:31:09 185
原创 主席树
给出一个数列,以及多次操作,操作可以是修改某一个数值,也可以是询问某一段区间的第K大数。思路:我们先考虑不带修改的区间第K大数,该如何用主席树求解。我们对于原序列进行离散化以及排序。线段树的节点所表示的区间【l,r】为排名在这个区间的个数有多少个。我们对于整个序列的所有前缀都建立一棵线段树,这里为了节省空间,这所有前缀的线段树将公用一些节点。每一棵前缀线段树都能表示前缀序列在相应的排名区间...
2019-02-21 19:21:38 61
原创 寻找道路
http://icpc.upc.edu.cn/problem.php?cid=1687&pid=4已知只有所有出边都直接或间接指向终点的点才可能被选择,所以就建反边,从终点想起点扫,dfs,bfs均可,在把所有终点不能达到的点打上标记,这些点均不可备选择,并且在反边图中这些点所指向的点也不能被选择(因为在正边图中这些点指向标记点)。因此可以删去图中不符合要求的点,然后跑最短路即可。...
2019-02-21 18:03:03 91
转载 C++STL(vector、set、map)的使用
版权声明:小简原创 https://blog.csdn.net/qq_43469554/article/details/87724499 &amp;lt;/div&amp;gt; &amp;lt;div id=&quot;content_views&quot; class=&quot;markdown_views prism-a
2019-02-19 19:17:48 1022
原创 进制转换
http://icpc.upc.edu.cn/problem.php?id=10264 #include<bits/stdc++.h>using namespace std;int n,m,i,j,k,k1,ans,b[10000],a[100000];char c[10000];int main(){ scanf("%d",&n); scanf(...
2019-02-19 13:13:59 56
转载 康托展开
康托展开的定义康托展开是一个全排列到一个自然数的双射,常用于构建哈希表时的空间压缩。 康托展开的实质是计算当前排列在所有由小到大全排列中的名次,因此是可逆的。原理介绍**X = A[0] * (n-1)! + A[1] * (n-2)! + … + A[n-1] * 0! **A[i] 指的是位于位置i后面的数小于A[i]值的个数,后面乘的就是后面还有多少个数的阶乘说明 :这个...
2019-02-18 16:44:10 47
原创 【快速幂】转圈游戏
http://icpc.upc.edu.cn/problem.php?cid=1685&pid=0#include<cstdio>using namespace std;int n,m,x,k,kk,i,j,ans=1;int main(){ scanf("%d%d%d%d",&n,&m,&k,&x); kk=10;...
2019-02-18 13:48:13 157
原创 积木大赛
http://icpc.upc.edu.cn/problem.php?cid=1685&pid=5#include <cstdio>using namespace std;int n,a[1000010],i,ans;int main(){ scanf("%d",&n); for(i=1; i<=n; i++) sca...
2019-02-18 13:29:18 428
原创 卡特兰数凸n+2边形的剖分计数
题意给定一个n多边形,要求用n-3条不相交的对角线把它分成n-2个三角形。求有多少种不同的方法。分析为什么是n-3条不相交的对角线...
2019-02-18 13:09:07 647
原创 阿卡分糖果
http://icpc.upc.edu.cn/problem.php?id=10590#include <cstdio>#define ll long longusing namespace std;int n,i,t,a[100005],s,l[100005],h[100005];ll ans;int main(){ scanf("%d",&n); fo...
2019-02-18 11:00:32 96
原创 Plague Inc
http://icpc.upc.edu.cn/problem.php?id=7553#include<cstring>#include<cstdio>#include<queue>using namespace std;int d[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};struct str{ int x,...
2019-02-18 10:50:46 175
转载 卡特兰数
实际问题的解决说了这么多,那么卡特兰数在实际问题中的应用还是很广泛的:经典问题:给出一个n,要求一个长度为2n的01序列,使得序列的任意前缀中1的个数不少于0的个数, 以下为长度为6的序列: 111000 101100 101010 110010 110100 证明: 令1表示进栈,0表示出栈,则可转化为求一个2n位,含n个1,n个0的二进制数, 满足从左...
2019-02-16 19:37:51 660
原创 Vigenère密码
http://icpc.upc.edu.cn/problem.php?cid=1683&pid=0观察运算®的规则表格发现该表格是左下和右上对称的,也就是说:可以认为加密时行标题是明文、列标题是密钥;也可以认为加密时行标题是密钥,列标题是明文。这里我们把行标题看做明文,列标题看做密钥。然后还可以发现:加解密运算规则表格的每一列其实是把行标题加上一个对应值就可以转换出来的。例如:表格...
2019-02-16 15:10:38 199
原创 同余方程
http://icpc.upc.edu.cn/problem.php?cid=1683&pid=4#include<iostream>#include<cstdio>#define ll long longusing namespace std;void exgcd(ll a,ll b,ll &x,ll &y){ if (b)...
2019-02-16 14:53:36 89
原创 借教室
http://icpc.upc.edu.cn/problem.php?cid=1683&pid=3#include<cstdio>#include<cstring>#define ll long longusing namespace std;ll sum,mid,L,R,i,j,a[1000010],n,m,r[1000010],d[1000010...
2019-02-16 14:52:40 61
原创 【分治】聪明的质检员
http://icpc.upc.edu.cn/problem.php?cid=1681&pid=1 #include<cstdio>#include<iostream>#include<cmath>#define N 200050#define ll long longusing namespace std;ll ans=1000000...
2019-02-15 15:15:28 149
原创 文化之旅
http://icpc.upc.edu.cn/problem.php?cid=1682&pid=3#include<cstdio>#include<cstring>using namespace std;int n,k,m,s,t,l,i,v[1000],j,d[1000],f1[1000][1000],f[1000][1000],a[1000],x,y...
2019-02-15 14:53:17 107
原创 【模拟】选择客栈
http://icpc.upc.edu.cn/problem.php?cid=1681&pid=4 用cnt[i]记录到i为止钱数不大于p的咖啡馆数目。枚举旅店b,寻找b之前与其颜色相等的旅店a,如果cnt[b]-cnt[b-1]>0则说明可行则ans++。时间为O(n^2),不足以应对n<=200000的数据范围。写了个小优化但效果并不理想。 别人的思路: ...
2019-02-15 14:04:29 152
原创 摆花
http://icpc.upc.edu.cn/problem.php?cid=1682&pid=2 用f[i][j]表示在前i个位置摆j盆花的方案数,状态转移方程也就出来了:f[i][j]=f[i-1][j-0]+f[i-1][j-1]+f[i-1][j-2]...+f[i-1][j-min(a[i],j)]a[i]存第i种最多摆的花数。然后显然需要三个循环,i,j同上,...
2019-02-15 13:49:57 251
原创 组装玩具
http://icpc.upc.edu.cn/problem.php?cid=1592&pid=7 贪心思路: (1) : 首先,按照tot从小到大排序,明确一点,影响答案的是最小的 tot ,所以,我们要把 m 尽可能多的用在 tot 小的材料上。 (2) : 从1开始往后遍历,查找和toy[1].tot相等的材料,判断 m 是否可以使其 +1,如果可以,toy...
2019-02-15 12:45:07 470
原创 查找特定的合数
http://icpc.upc.edu.cn/problem.php?id=10187#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<set>#include<que...
2019-02-15 12:16:02 406
原创 Color a Tree
http://icpc.upc.edu.cn/problem.php?cid=1430&pid=19结论1:对于一个非根结点,它具有非根结点的最大权值,那么访问完它的父亲后就要立即访问它才能使得代价最小。处理过程:1)建立结构体node,结构体数组e[i]表示i结点的状态,e[i].c=ci为总权值,e[i].w=ci为当前权值,e[i].t=1为经过这个结点需要的耗时(也可以...
2019-02-15 12:12:01 383
原创 H - 大水题
https://vjudge.net/contest/280305#problem/H#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int i,n,a[400],kk,k,len,ans,sum[400],dp...
2019-02-15 11:23:01 123
原创 K - 被AK题
https://vjudge.net/contest/280305#problem/K#include<iostream>#include<cstdio>#include<cstring>using namespace std;int i,j,t,n,kk,a[1000],dp[1000][1000];int main(){ scanf...
2019-02-15 11:22:54 143
原创 摆动序列
http://icpc.upc.edu.cn/problem.php?id=1621#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;int a[1000000],m,n,j,i,ans,v[25];int...
2019-02-15 11:22:19 288
原创 K - Insertion Sort
https://vjudge.net/contest/278754#problem/K#include<cstdio>#define ll unsigned long longusing namespace std;const int mod = 1e9+7;ll t,ii,i,n,k,ans,sum,q,now;int main(){ scanf("%llu...
2019-02-15 11:22:06 103
原创 荷马史诗
http://icpc.upc.edu.cn/problem.php?cid=1431&pid=14#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespace std;struct str{ long long...
2019-02-15 11:22:01 200
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人