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 ...
随机推荐
- linux route命令学习
route命令用于显示和操作IP路由表. 没有增加路由之前,route命令的结果如下, sh-# route Kernel IP routing table Destination Gatew ...
- LINUX 文件系统JBD ----深入理解Fsync
http://www.cnblogs.com/hustcat/p/3283955.html http://www.cnblogs.com/zengkefu/p/5639200.html http:// ...
- Python 基础学习
http://www.cnblogs.com/Wxtrkbc/p/5486253.html
- tuple类型的单词查询例子
17.3 重写前面的TextQuery程序,使用tuple代替QueryResult类. TextQuery.h #ifndef TEXTQUERY_H #define TEXTQUERY_H #in ...
- Linux ssh/scp连接时避免输入yes(公钥验证)并防止出现POSSIBLE BREAK-IN ATTEM
方法一:连接时加入StrictHostKeyChecking=no ssh -o StrictHostKeyChecking=no root@192.168.1.100 方法二:修改/etc/ssh/ ...
- idea集成svn插件
1.需要在机器上安装一个SVN客户端命令行程序,可以到这里下载对应的安装程序:http://subversion.apache.org/packages.html#windows 我选择的是torto ...
- 常用js代码学习
1.用JS实现的radio图片选择按钮效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...
- jar打包通过exe4j转换成exe文件
去年的时候有用过,最近写java的时候偶然用到,mark一下,方便以后看 下载链接后面附上 首先我们在eclipse上打包成jar文件,我这里只把简单的截图贴出来,详细的可以自行百度 打包jar文件: ...
- 一个js 变量作用域问题
一个js 域问题,有一本书 叫 javasrcip pattert 好像是,写的很好,, <!DOCTYPE html> <html> <head lang=" ...
- 使用Github建立个人博客
总的说来 这个当有node.js 和gitbub的账号后,搭建一个自己的博客,想想还是挺美的事! 由于要把整个流程说清楚 估计lz还没这个实力,所以都是继承前辈们的经验,自己再添加一点遇到的问题和解决 ...