Codeforces Round #Pi (Div. 2)
上次比完赛就准备写了, 结果懒癌发作了, 拖到了现在。
Problem_A:
题意:
在一条x轴上有n座城市, 每个城市之间的距离就是它们对应坐标的距离, 现在求出每个城市到其他城市的最近距离和最远距离。
思路:
最远的必然在最左右端点产生, 因为没有比它们还远的城市了。
最近的必然在相邻左右端点产生,因为有没比它们还近的城市了。
比较下即可, 注意处理最左右端点时的情况。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define dd cout<<"debug"<<endl
#define p(x) cout<<x<<endl
int n;
int x[MAXN]; int main()
{
scanf("%d", &n);
for(int i = ; i < n; i ++)
scanf("%d", &x[i]);
for(int i = ; i < n; i ++)
{
if(i == )
printf("%d ", x[i + ] - x[i]);
else if(i == n - )
printf("%d ", x[i] - x[i- ]);
else
printf("%d ", min(x[i] - x[i - ], x[i + ] - x[i])); if(i == n - )
printf("%d\n", x[i] - x[]);
else if(i == )
printf("%d\n", x[n - ] - x[i]);
else
printf("%d\n", max(x[i] - x[], x[n - ] - x[i]));
}
return ;
}
Problem_B:
题意:
一个图书馆中有一个记录人员进出的机器, 现在你根据这台机器的进出记录计算一下这图书馆能容纳的最小人数。
图书馆的机器不是24小时开启, 这意味着有可能在它开机之前就有人进入图书馆并且在它开机后出去。
思路:
计算图书馆进出记录中, 同时有多少人在里面, 如果有人出来, 并且没有进入记录, 那么他在之前就已经进去, 这时候最小容纳人数需 + 1。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000010
#define dd cout<<"debug"<<endl
#define p(x) cout<<x<<endl
int n;
bool in_r[MAXN]; int main()
{
int in = , out = ;
int max_in = ;
scanf("%d", &n);
getchar();
memset(in_r, false, sizeof(in_r));
for(int i = ; i < n; i ++)
{
char ch;
int r;
scanf("%c %d", &ch, &r);
getchar();
if(ch == '+')
{
in_r[r] = true;
in ++;
if(in > max_in) max_in = in;
}
else if(ch == '-')
{
if(in_r[r] == false)
{
max_in ++;
}
else
{
in_r[r] = false;
in --;
}
}
}
printf("%d\n", max_in);
return ;
}
Problem_C:
题意:
给n个数, 一个公比k。
问数列中有多少个三元集满足 是一个公比为k的等比数列。集合中的顺序不能交换, 即只能根据给定的顺序计算。
思路:
枚举中值bk, 计算在它之前有多少个b, 在它之后又多少个bk^2, 则这个中值的贡献值为这两个数之积。
hash,map均可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 200010
#define dd cout<<"debug"<<endl
#define p(x) cout<<x<<endl
int n;
LL k;
LL ans;
LL x[MAXN];
LL l_num[MAXN], r_num[MAXN];
map<LL, LL> m;
void cal_right()
{
m.clear();
for(int i = n - ; i >= ; i --)
{
map<LL, LL>::iterator m_ = m.find(x[i] * k);
if(m_ != m.end())
r_num[i] = m[x[i] * k];
m[x[i]] ++;
}
}
void cal_left()
{
m.clear();
ans = ;
for(int i = ; i < n; i ++)
{
if(x[i] % k == )
{
map<LL, LL>::iterator m_ = m.find(x[i] / k);
if(m_ != m.end())
l_num[i] = m[x[i] / k];
}
m[x[i]] ++;
}
} int main()
{
scanf("%d %lld", &n, &k);
for(int i = ; i < n; i ++)
scanf("%lld", &x[i]);
cal_right();
cal_left();
for(int i = ; i < n; i ++)
ans = ans + l_num[i] * r_num[i];
printf("%lld\n", ans);
return ;
}
Problem_D:
题意:
给你一段长度为n的区间, 你在这区间内放置k只船只,每只船只的长度为a, 每两只船不能接触。
你的朋友告诉你一些点是不能放置船只的, 你来判断你的朋友说的是否为真话。
如果为假, 则输出你的朋友说出来的第几个点是不满足放置k只船只的。
思路:
每得到一个点, 就将整个区间的划分数 + 1, 计算每次划分是否满足题意即可。
划分之后的放置船只数 = 总的划分数 - 这个点所在最小区间的放置数 + 将这个区间划分后所形成的两个新区间的放置数。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define dd cout<<"debug"<<endl
#define p(x) cout<<x<<endl
int n, k, a;
int m;
set <int> s; int main()
{
scanf("%d %d %d", &n, &k, &a);
scanf("%d", &m);
s.insert();
s.insert(n + );
int ans = (n + ) / (a + );
int ans_id = -;
for(int i = ; i < m; i ++)
{
int x;
scanf("%d", &x);
if(ans < k) continue;
s.insert(x);
set <int>::iterator s_ = s.find(x);
int l = *(-- s_);
int r = *(++ (++ s_));
//p(l),p(r),p(ans);
ans = ans - (r - l) / (a + );
ans = ans + (x - l) / (a + ) + (r - x) / (a + );
//p((r - l) / (a + 1)),p((x - l) / (a + 1)),p((r - x) / (a + 1)),p("\n");
if(ans < k) ans_id = (i + );
}
printf("%d\n", ans_id);
return ;
}
太阳出来了, 看着朝阳升起也是一种不错的体验, very nice.
没有做的题待搞懂做完后再将题解加进来吧~
Codeforces Round #Pi (Div. 2)的更多相关文章
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞
D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #Pi (Div. 2) C. Geometric Progression map
C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library set
B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水
A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...
- Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥
题目链接: http://codeforces.com/contest/567/problem/E 题意: 给你一个带重边的图,求三类边: 在最短路构成的DAG图中,哪些边是必须经过的: 其他的(包括 ...
- Codeforces Round #Pi (Div. 2) E. President and Roads tarjan+最短路
E. President and RoadsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567 ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟
B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
随机推荐
- mongnodb 启动脚本
开始用mongodb建立一套监控体系,安装解压即可.附上编写的mongodb启动管理脚本. 建议 mkdir sbin 目录,放到sbin目录下.废话少说,代码如下: #!/bin/bash MONG ...
- 三分钟学会缓存工具DiskLruCache
DiskLruCache是一个十分好用的android缓存工具,我们可以从GitHub上下载其源码:https://github.com/JakeWharton/DiskLruCache DiskLr ...
- Android UI 开发
今天主要学习了Android UI开发的几个知识 6大布局 样式和主题→自定义样式.主题 JUnit单元测试 Toast弹窗功能简介 6大布局 RelativeLayout LinearLayout ...
- nginx介绍及安装
nginx(Engine x) 静态的www软件 特点: 配置简单 高并发,1-2w,基于异步IO模型(epoll,kqueue) 占用资源少 ...
- Google C++ Style Guide在C++11普及后的变化
转 http://www.cnblogs.com/chen3feng/p/5972967.html?from=timeline&isappinstalled=0&lwfrom=user ...
- Sqlserver通过链接服务器访问Oracle的解决办法
转自http://blog.sina.com.cn/s/blog_614b6f210100t80r.html 一.创建sqlserver链接服务(sqlserver链接oracle) 首先sqlse ...
- [C# 基础知识系列]专题十六:Linq介绍
转自http://www.cnblogs.com/zhili/archive/2012/12/24/Linq.html 本专题概要: Linq是什么 使用Linq的好处在哪里 Linq的实际操作例子— ...
- 消息处理之EventBus ——使用篇
以前的几篇文章简单的介绍了一下UI线程和子线程之间的线程通信利器Handler,以及顺便介绍了一下SyncTask和HeadlerThread.这里介绍另一线程通信利器EventBus. EventB ...
- 使用dojo遮罩加载进度。
使用dojox.widget.Standby来实现类似视频缓冲加载时候转圈的效果.
- iOS RegexKitLite的使用以及常用的正则表达式
1.去RegexKitLite下载类库,解压出来会有一个例子包及2个文件,其实用到的就这2个文件,添加到工程中. 2.工程中添加libicucore.dylib frameworks. 3.现在所有的 ...