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

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. rnqoj-99-配置魔药-dp

    比较好的题目~~ dp[j][k]: 第一个容器在第i秒和第二个容器在第j秒,所产生的最大魔力. if(num[i].t2<=j)dp[j][k]=max(dp[j][k],dp[num[i]. ...

  2. mybatis15 mapper方式 代码

    UserMapper.java package cn.itcast.mybatis.mapper; import java.util.List; import cn.itcast.mybatis.po ...

  3. 标准库function类型的使用

    14.44编写一个简单的桌面计算器使其能处理二元运算. #include<iostream> #include<map> #include<functional> ...

  4. Mac上pod install一直停住的解决办法

    pod install一直停住的解决办法 在/Users/XXX/.cocoapods/repos下 git clone https://github.com/CocoaPods/Specs.git ...

  5. 用标准版的Eclipse搭建PHP环境

    用标准版的Eclipse搭建PHP环境 ——@梁WP 摘要:用标准版的Eclipse搭建PHP环境. 一.下载Eclipse的PHP插件 百度搜索phpeclipse,看到某条结果是带有SourceF ...

  6. favicon.ico显示,favicon显示,favicon图标显示

    favicon.ico显示,favicon显示,favicon图标显示 >>>>>>>>>>>>>>>> ...

  7. css 导航条 布局

    导航条(简单易用的导航) <!DOCTYPE html> <html> <head> <style> ul { list-style-type:none ...

  8. .NET设计模式(8):适配器模式(Adapter Pattern)

    ):适配器模式(Adapter Pattern)    适配器模式(Adapter Pattern) --.NET设计模式系列之八 Terrylee,2006年2月 概述 在软件系统中,由于应用环境的 ...

  9. java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

    在使用Fragment的过程中,常常会遇到在Activity的onSaveInstanceState方法调用之后,操作commit或者popBackStack而导致的crash. 因为在onSaveI ...

  10. JMeter对Selenium自动化代码进行压测

    原文转载:http://www.blogjava.net/qileilove/archive/2014/06/05/414423.html 准备工作: 将文件selenium-server-stand ...