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

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. [TypeScript] Using Lodash in TypeScript with Typings and SystemJS

    One of the most confusing parts of getting started with TypeScript is figuring out how to use all th ...

  2. 使用QEMU调试Linux内核代码

    http://blog.chinaunix.net/uid-20729583-id-1884617.html http://www.linuxidc.com/Linux/2014-08/105510. ...

  3. Linux模式设计系列( 内核与应用关联思考)

    http://blog.chinaunix.net/uid/20608849/cid-25333-list-2.html

  4. GDB 调试程序系列

    http://blog.csdn.net/haoel/article/category/9197

  5. 从源码角度理解android动画Interpolator类的使用

    做过android动画的人对Interpolator应该不会陌生,这个类主要是用来控制android动画的执行速率,一般情况下,如果我们不设置,动画都不是匀速执行的,系统默认是先加速后减速这样一种动画 ...

  6. Android(java)学习笔记181:利用Service在后台播放背景音乐

    1.在android应用程序里,有一种没有UI的类(android.app.Service)——Service.简单来说,Service是一个 background process(背景程序),通过背 ...

  7. Js判断对象是否为空,Js判断字符串是否为空

    Js判断对象是否为空,Js判断字符串是否为空,JS检查字符串是否为空字符串 >>>>>>>>>>>>>>>&g ...

  8. Codeforces Round #310 (Div. 2)--B

    http://codeforces.com/problemset/problem/556/B 题意:给定n个数字且都小于n,然后每次循环第2k+1个数字+1,第2k个数字减一,k=0,1,2...n/ ...

  9. java问题:类的定义,对象的定义?

    java问题:类的定义,对象的定义? 类是一组数据和函数的集合,只是抽象的概念,它的作用就是生成对象,它生成对象后,就为这个对象分了一块存储区,类可以生成无限多个对象,每个对象都有自己的存储区,在类里 ...

  10. 【转】Java中equals和==的区别

    [转]Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boole ...