上次比完赛就准备写了, 结果懒癌发作了, 拖到了现在。

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)的更多相关文章

  1. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  2. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  3. 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 ...

  4. 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 ...

  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 ...

  6. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...

  7. Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥

    题目链接: http://codeforces.com/contest/567/problem/E 题意: 给你一个带重边的图,求三类边: 在最短路构成的DAG图中,哪些边是必须经过的: 其他的(包括 ...

  8. 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 ...

  9. 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 ...

  10. Codeforces Round #Pi (Div. 2) B. Berland National Library 模拟

    B. Berland National LibraryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

随机推荐

  1. 苹果电脑出现 .DS_Store文件,删除不掉怎么处理?

    今天早上打开电脑,发现桌面上出现一个.DS_Store文件.可是出现的莫名其妙,也就没在意,可是重复删除之后还是出现.后来查了一下网上的资料,才知道,昨天我加入git的时候,为了看见 .git这个隐藏 ...

  2. careercup-数组和字符串1.2

    1.2 用C或C++实现void reverse(char *str)函数,即反转一个null结尾的字符串. C++实现代码: #include<iostream> #include< ...

  3. linux解压缩命令

    1.tar -cvf /data/sc2.tar /data (只打包,不压缩) 把/data下的文件打包成 sc.tar  上面两个都是绝对路径噢 tar -zcvf /data/sc2.tar.g ...

  4. WPF自定义窗体仿新毒霸关闭特效(只能在自定义窗体中正常使用)

    比较简单的一个小功能,和新毒霸类似的效果. 效果代码: bool closeStoryBoardCompleted = false; DoubleAnimation closeAnimation1; ...

  5. vc++ 最小化到托盘的详细实现

    在VC++中,想实现将MFC最小化到系统托盘,需要调用NOTIFYICONDATA类,并注册相应的消息,以下详细讲解如何实现: 1.声明一个NOTIFYICONDATA类,也就是NOTIFYICOND ...

  6. extSourceStat_7Day_Orders.php

    <?php /** Log文件格式2012/7/4 列号 字段含义 取值 ------------------------------------------------------------ ...

  7. php 半角与全角相关的正则

    半角的全部确认,带小初音的确认法则 ^[ア-ン゙゚ァ-ョッヲー -]+$ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset// ...

  8. Jenkins corbertura问题

    最近在Jenkins上部署项目时遇到无法展示覆盖率测试报告的问题. build success后,出现配置的覆盖率报告存储位置not exists的失败问题,评估是Jenkins每次按照publish ...

  9. Sql解锁 数据库死锁检测

    USE [DataBaseName]GO/****** Object:  StoredProcedure [dbo].[sp_check_deadlock]    Script Date: 07/04 ...

  10. jQuery实现多级手风琴树形下拉菜单(源码)

    前几天因为公司的菜单要调整,公司的UI框架是不支持的,所以就自己在网上找了一个下拉菜单,可以支持多级菜单数据的,菜单数据是从xml文件中配置后读取的,网上有许多这方面的例子感觉不是很好用,就打了个包贴 ...