
Codeforces
ShellDawn
Gu-Ah
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
No.165 - Codeforces-Contest-1282 - B
n个物品,每个物品对应价格。 有种优惠,买物品A可以附赠价值小于A的k-1件商品 则,现有p数量钱,最多买几件物品? 原问题:优惠必须选k-1件赠品,多和少都不可以 思路:k间隔枚举,再在从小价值物品里面挑 #include<cstdio> #include<cstring> #include<algorithm> #include<cstring>...原创 2019-12-25 00:41:43 · 172 阅读 · 0 评论 -
Codeforces 1131F (并查集,union-find sets)
用并查集构造一颗树即可。 关键在于fa()中的合并路径,更新父节点,但不更新子节点。 方法1,速度较快,内存占用小,不直观: #include &lt;cstdio&gt; #include &lt;algorithm&gt; #include &lt;vector&gt; #include &lt;cstring&gt; using namespace std; #defin原创 2019-02-24 18:22:53 · 453 阅读 · 0 评论 -
codeforces:1140C(greedy)
贪心 typedef long long ll; #include<bits/stdc++.h> using namespace std; #define maxn 300050 struct Sang{ ll x,y; bool operator < (const Sang & t) const{ return y > t.y...原创 2019-03-25 20:11:18 · 358 阅读 · 0 评论 -
codeforces:1144F(DFS)
无向图找奇数环,顺带更新边方向: #include<bits/stdc++.h> using namespace std; #define maxn 200005 int n,m; vector<pair<int,int> > e[maxn]; int color[maxn]; int ans[maxn]; bool res; void dfs(int f...原创 2019-04-01 16:07:21 · 450 阅读 · 0 评论 -
codeforces:1152C(math)
Euclidean Algorithm: 找lsm(a+k,b+k)等同于找gcd(a+k,b+k) 其中: gcd(a+k,b+k) = gcd(a+k,b-a) 枚举b-a所有因子即可,通过因子找a+k,然后再找k #include<bits/stdc++.h> using namespace std; #define LL long long LL a,b; LL minlsm...原创 2019-04-25 19:36:31 · 396 阅读 · 0 评论 -
codeforces:1141E(implement)
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; const int inf = 0x3f3f3f3f; long long num[maxn]; int main(){ memset(num,0,sizeof(num)); long long H,n; scanf("...原创 2019-04-22 14:56:52 · 199 阅读 · 0 评论 -
Codeforce:Round 568 div2 D
模拟: 要么删第一个,要么删第二个,要么删之后中间的 第一个和第二个需要确定等差值 #include<bits/stdc++.h> using namespace std; #define maxn 200005 int n; struct Node{ int id; long long v; }; Node num[maxn]; bool cmp(const ...原创 2019-06-20 01:01:00 · 211 阅读 · 0 评论 -
No.34 - Codeforces777B 田忌赛马 贪心
题目要求给出两种策略: 1,田忌要尽可能少输 2,田忌要尽可能多赢 无非就是改变赢局和平局的比例。 当尽可能少输时,那就要先采取平局,然后再尽量取胜,剩下就是必输了。 当尽可能多赢时,那就要先尽量取胜,然后尽量平局,剩下就是必输了。 枚举时暴力做的,可能比最优双端队列贪心要慢。 // ShellDawn // Codeforces 777B // No.34 #include<stdio....原创 2019-07-29 17:34:34 · 240 阅读 · 0 评论 -
Codeforces 896A
/* * 20171205 */#include <cstdio> #include <algorithm> #include <cstring>using namespace std;char F[] = "What are you doing at the end of the world? Are you busy? Will you save us?"; char A[] = "What a原创 2017-12-07 00:54:10 · 372 阅读 · 0 评论 -
Codeforces785C (math,binary search)
安东和童话 每个测试的时间限制1秒 每个测试的内存限制256兆字节 输入标准输入 输出标准输出 安东喜欢听童话故事,特别是安东的好朋友丹尼克告诉他们的时候。现在丹尼克告诉安东一个童话故事:“有一天,他住了一个皇帝,他很富有,有很多粮食,有一天,他命令建立一个巨大的谷仓,把所有的粮食,最好的建设者建造谷仓三天三夜,但他们忽视了,在谷仓里还有一个小洞,每天麻雀都从中穿过,这里飞过一只麻雀,拿了原创 2017-03-23 15:46:00 · 357 阅读 · 0 评论 -
Codeforces 895B (stl binary search)
想好左右界,以及边界可以整除的情况。 注意,左界可能存在小于ai的情况,这种是不合法的。/* * 20171128 */#include <cstdio> #include <algorithm>using namespace std;#define maxn 100010int n; long long x,k; long long num[maxn];int main() { scan原创 2017-11-27 14:44:05 · 400 阅读 · 0 评论 -
Codeforces 879B (implement)
题目注意两个地方:一个是k的取值范围太大,需要longlong保存,一个是除了第一位的胜场是从0计数,剩下n-1位的胜场都是从1计数。/* * 20171028 */#include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <cstdlib>using namespace std;int p原创 2017-10-28 10:04:04 · 646 阅读 · 0 评论 -
Codeforces 839B (implement)
累心的模拟题: 附上几个特殊样例:3 10 2 2 2 2 2 2 2 2 2 3 YES 3 12 2 2 2 2 2 2 2 2 2 1 1 1 YES 2 8 2 2 2 2 2 2 1 1 YES 1 4 1 1 2 2 YES 1 4 2 2 2 2 NO代码:/* * 201708016 */#include <cstdio> #include <algorithm> #include原创 2017-08-16 17:02:45 · 348 阅读 · 0 评论 -
Codeforces 467C (dp,prefix sum)
预处理,求出prefix_sum[]前缀和数组 然后二维dp,转移方程:dp[i][j] = max(dp[i][j-1],dp[i-1][j-m]+prefix_sum[j]-prefix_sum[j-m]);#include <cstdio> #include <cstring> #include <algorithm>using namespace std;#define maxn 5010原创 2017-03-28 16:41:03 · 573 阅读 · 0 评论 -
Codeforces 672A(implementation)
问题描述:一个有趣常见的问题,将从1开始的数字首尾相接全部连在一起,那么,第n个字符是那个0-9的数字字符?#include <cstdio> #include <algorithm>using namespace std;int main() { int n; scanf("%d",&n); int ans = n; //ans是最后的结果 int maxplace =原创 2017-04-12 11:06:40 · 557 阅读 · 0 评论 -
Codeforces 520B (bfs,dp,dfs,greedy)
做法一,入门级dp,转移方程:dp[i] = min(dp[i],dp[i/2]+1,dp[i+1]+1); //i为偶数 dp[i] = min(dp[i],dp[i+1]+1);//i为奇数由于转移方程涉及两个方向,故选用while套for双重循环#include <cstdio> #include <algorithm>using namespace std;#define maxn 1005原创 2017-03-27 01:51:05 · 991 阅读 · 0 评论 -
Codeforces 492E (math)
很有意思的一道题: 在正方形中按一个固定向量走,路过最多的特殊点。 注意,dx与n互质,dy与n互质,意味着走n步必然回到起点,且路径上同一个横坐标只会对应一个纵坐标。 所以,就简化成一个分类计数问题。#include <cstdio> #include <algorithm> #include <cstring>using namespace std;#define maxn 1000010原创 2017-03-28 00:13:21 · 553 阅读 · 0 评论 -
Codeforces484A (strings,bitmasks)
第一种做法,字符串模拟 注意0和0情况 分l和r二进制位数相同和不同两种情况,这两种情况,r都有可能是答案 #include <cstdio> #include <cstring>void to_binary(long long num,int str[],int& mx) { int cnt=0; while(num!=0) { if(num&1) str[原创 2017-03-23 18:03:06 · 516 阅读 · 0 评论 -
Codeforces 895A (入门 prefix sum)
/* * 20171128 */#include <cstdio> #include <algorithm>int n; int num[400]; int prefixSum[400];int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&num[i]); pr原创 2017-11-27 12:36:10 · 437 阅读 · 0 评论