CF-558:部分题目总结
题目链接:http://codeforces.com/contest/1163
A .Eating Soup
sol:在n / 2、n - m、m三个数中取最小值,结果受这三个值限制。但是m == 0的情况需要特判
- 思维
- #include "bits/stdc++.h"
- using namespace std;
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- if (m == ) {puts(""); return ;}
- printf("%d\n", min(n >> , min(n - m, m)));
- return ;
- }
没有考虑n - m导致了一发wa,而且想了一定时间。好像有点生疏了,哎。
- #include "bits/stdc++.h"
B1 .Cat Party (Easy Edition)
sol:在这一题中u[i]的范围只有10,可以用循环来尝试删除,并判断删除后可否满足题目要求,然后记录;
- 暴力
- #include "bits/stdc++.h"
- using namespace std;
- const int MAXN = 1e5 + ;
- int cnt[MAXN];
- int ans, n, k;
- bool check() {
- int k = -;
- for (int i = ; i <= ; i++) {
- if (cnt[i]) {
- if (k == -) k = cnt[i];
- else if (k != cnt[i]) return false;
- }
- }
- return true;
- }
- int main() {
- scanf("%d", &n);
- for (int i = ; i <= n; i++) {
- scanf("%d", &k);
- cnt[k]++;
- /*
- 做B2的时候意识到每次删除的要么是只出现一次的数要么是出现次数最多的数
- 所以这个循环可以改成找最大值,然后检查一下最大值和1就行了
- */
- for (int j = ; j <= ; j++) {
- if (cnt[j]) {
- cnt[j]--;
- if (check()) ans = i;
- cnt[j]++;
- }
- }
- }
- printf("%d\n", ans);
- return ;
- }
- #include "bits/stdc++.h"
B2 .Cat Party (Hard Edition)
sol:每次删除的数要么是只出现一次的,或者是出现次数最多的。但是暴力找要超时,所以我就用STL里的multiset来了一波优化后的暴力。把思维题做成了暴力;
- 带优化暴力
- #include "bits/stdc++.h"
- using namespace std;
- const int MAXN = 1e5 + ;
- multiset<int> st;
- multiset<int>::iterator it;
- int cnt[MAXN];
- int ans, n, k;
- int main() {
- scanf("%d", &n);
- for (int i = ; i <= n; i++) {
- scanf("%d", &k);
- if (cnt[k]) {
- it = st.find(cnt[k]);
- st.erase(it);
- }
- cnt[k]++;
- st.insert(cnt[k]);
- // 特判只有一种数字
- if (st.size() == ) {
- ans = i;
- continue;
- }
- if (*st.begin() == ) {
- st.erase(st.begin());
- if (*st.begin() == *(--st.end())) ans = i;
- st.insert();
- }
- it = --st.end();
- k = *it;
- st.erase(it);
- if (*st.begin() == k - && *(--st.end()) == k - ) ans = i;
- st.insert(k);
- }
- printf("%d\n", ans);
- return ;
- }
思维果然跟不上队友,只能靠STL这种道具。队友想到了正解
- #include "bits/stdc++.h"
sol:这题的正解是数据结构,用两个数组a和b,a[i]表示数字i出现几次,b[i]表示出现i次的数有几个
- 数据结构
- #include "bits/stdc++.h"
- using namespace std;
- const int MAXN = 1e5 + ;
- int a[MAXN], b[MAXN];
- int n, k, mx, ans;
- int main() {
- scanf("%d", &n);
- for (int i = ; i <= n; i++) {
- scanf("%d", &k);
- b[a[k]]--;
- a[k]++;
- b[a[k]]++;
- mx = max(mx, a[k]);
- if (b[] == i) ans = i;
- else if (b[i] == ) ans = i;
- else if (b[] == && b[mx] * mx == i - ) ans = i;
- else if ((b[mx - ] + ) * (mx - ) == i - ) ans = i;
- }
- printf("%d\n", ans);
- return ;
- }
- #include "bits/stdc++.h"
- 别人同思路的代码
- #include <bits/stdc++.h>
- using namespace std;
- int64_t n,x,ans;
- map<int,int>a,b;
- int main()
- {
- cin>>n;
- ans=;
- for(int i=;i<=n;i++)
- {
- cin>>x;
- a[x]++;b[a[x]]++;
- if(a[x]*b[a[x]]==i&&i!=n) ans=i+;
- if(a[x]*b[a[x]]==i-) ans=i;
- }
- cout<<ans;
- }
看到一份别人的思路差不多的代码,但是他用了map代码很整洁,贴一下。
C .Power Transmission
sol:将所有点两两配对,两个点确定一条直线,求出直线方程一般式的a、b、c。将a和b约分后去重。对于每条边,加一次和自己斜率不同的边的个数就行了。
- 几何
- #include "bits/stdc++.h"
- using namespace std;
- typedef pair<int, int> PII;
- typedef long long LL;
- const int MAXN = ;
- PII p[MAXN];
- map<PII, set<LL> > mp;
- LL tot, ans;
- int main() {
- int n;
- scanf("%d", &n);
- for (int i = ; i <= n; i++)
- scanf("%d%d", &p[i].first, &p[i].second);
- for (int i = ; i <= n; i++) {
- for (int j = ; j < i; j++) {
- int x1 = p[i].first, y1 = p[i].second;
- int x2 = p[j].first, y2 = p[j].second;
- int a = y2 - y1, b = x1 - x2, g = __gcd(a, b);
- a /= g, b /= g;
- LL c = - a * 1LL * x2 - b * 1LL * y2;
- if (mp[{a, b}].count(c) == ) {
- mp[{a, b}].insert(c);
- tot++;
- ans += tot - mp[{a, b}].size();
- }
- }
- }
- printf("%lld\n", ans);
- return ;
- }
以前学的直线方程什么的都忘的差不多了,看出题人的标程里面求c的过程还以为是hash。花了好久才搞明白,提交了十几发。也算收获不小。
- #include "bits/stdc++.h"
CF-558:部分题目总结的更多相关文章
- CF 558 C. Amr and Chemistry 暴力+二进制
链接:http://codeforces.com/problemset/problem/558/C C. Amr and Chemistry time limit per test 1 second ...
- CF 558 C
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...
- CF 题目选做
写省选的题目对noip没什么大用 关键是 细节题或者是思考题比较重要 练思维自然是CF比较好了 把我见到的比较好的CF题放上来刷一刷. LINK:Complete the projects 就是说一个 ...
- uva 558 - Wormholes(Bellman Ford判断负环)
题目链接:558 - Wormholes 题目大意:给出n和m,表示有n个点,然后给出m条边,然后判断给出的有向图中是否存在负环. 解题思路:利用Bellman Ford算法,若进行第n次松弛时,还能 ...
- TopCoder SRM 558 Div 1 - Problem 1000 SurroundingGame
传送门:https://284914869.github.io/AEoj/558.html 题目简述 一个人在一个n * m棋盘上玩游戏,想要占领一个格子有两个方法: 在这个格子放一个棋子. 这个 ...
- CF 219D 树形DP
CF 219D [题目链接]CF 219D [题目类型]树形DP &题意: 给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v>,如果v要到 ...
- 跟着xiaoxin巨巨做cf
cf 385 C. Bear and Prime Numbers 题目大意:有一个数列{xi},每次给出一个询问[l, r],即问 S(l ,r)是l和r之间的素数,f(p)表示数列{xi}中整除p的 ...
- codeforces 558B. Amr and The Large Array 解题报告
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...
- Codeforces Round #379 (Div. 2) 解题报告
题目地址 本次CF是在今天早上深夜进行,上午有课就没有直接参加.今天早上上课坐到后排参加了virtual participation.这次CF前面的题目都非常的水,不到10分钟就轻松过了前两题,比较郁 ...
- Miaomiao's Geometry
HDU 4932 Bestcoder Problem Description There are N point on X-axis . Miaomiao would like to cover t ...
随机推荐
- SQL基础教程(第2版)第3章 聚合与排序:3-1 对表进行聚合查询
3-1 对表进行聚合查询 ● 使用聚合函数对表中的列进行计算合计值或者平均值等的汇总操作.● 通常,聚合函数会对NULL以外的对象进行汇总.但是只有COUNT函数例外,使用COUNT(*)可以查出包含 ...
- 拷贝构造函数[c++]
拷贝构造函数何时会被调用? 1. 对象以值传递的方式传入函数参数 2.对象以值传递的方式从函数返回 3.对象需要通过另外一个对象进行初始化 下面我们来看代码: //#include <iostr ...
- 2. laravel 5.5 学习 过程中 遇到问题 的 链接
关于 laravel 5.5 的文档 网络上已经太多 就不些太多重复的话了 在以后的 工作 中遇到问题的 查询到的解决方案 或者 相关文档将会具体写在这里 laravel 5.5 中文文档 https ...
- 基于Token的身份验证
最近了解下基于 Token 的身份验证,跟大伙分享下.很多大型网站也都在用,比如 Facebook,Twitter,Google+,Github 等等,比起传统的身份验证方法,Token 扩展性更强, ...
- 12 Spring Data JPA:orm思想和hibernate以及jpa的概述和jpa的基本操作
spring data jpa day1:orm思想和hibernate以及jpa的概述和jpa的基本操作 day2:springdatajpa的运行原理以及基本操作 day3:多表操作,复杂查询 d ...
- 负载均衡配置篇(Nginx)
负载均衡 == 分身的能力. 既然要有分身的能力嘛,这好办,多弄几台服务器就搞定了.今天我们讲的实例嘛…..我们还是先看图比较好: 还是图比较清晰,以下我都用别名称呼: PA : 负载均衡服务器/WE ...
- Disruptor的简单介绍与应用
前言 最近工作比较忙,在工作项目中,看了很多人都自己实现了一套数据任务处理机制,个人感觉有点乱,且也方便他人的后续维护,所以想到了一种数据处理模式,即生产者.缓冲队列.消费者的模式来统一大家的实现逻辑 ...
- ccf201403-3 记录一个神tmwa了的代码 莫非我没看懂题。。。
#include <string.h> #include<cstdio> #include<stdio.h> #include <iostream> # ...
- Vue专题-生命周期
有时候,我们需要在实例创建过程中进行一些初始化的工作,以帮助我们完成项目中更复杂更丰富的需求开发,针对这样的需求,Vue提供给我们一系列的钩子函数. 本文详细介绍了Vue实例在创建和销毁的过程中,我们 ...
- goweb-文本处理
文本处理 Web开发中对于文本处理是非常重要的一部分,我们往往需要对输出或者输入的内容进行处理,这里的文本包括字符串.数字.Json.XML等等.Go语言作为一门高性能的语言,对这些文本的处理都有官方 ...