567A Lineland Mail
题意:一些城市在一个x轴上,他们之间非常喜欢写信交流。送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用。

没什么好说的。直接做。特判最左边的和最右边的。
其它的最小值在相邻的城市取,最大的在两边的城市与本城市取最大值。

代码:

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <functional>
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
#define sf(a) scanf("%d",&a)
#define sff(a,b) scanf("%d%d",&a,&b)
#define sfff(a,b,c) scanf("%d%d%d",&a,&b,&c)
const int INF = 0x7FFFFFFF;
const int MAXN = 201000;
const double PI = acos(-1.0);
const double esp = 1e-10;
using namespace std;
int data[MAXN];
int main()
{
int n;
sf(n);
for(int i=1;i<=n;i++)
{
sf(data[i]);
}
for(int i=1;i<=n;i++)
{
if(i == 1)
printf("%d %d\n",data[2] - data[1],data[n] - data[1]);
else if(i==n)
printf("%d %d\n",data[n] - data[n-1],data[n] - data[1]);
else
printf("%d %d\n",min(data[i+1] - data[i],data[i]-data[i-1]),max(data[i]-data[1],data[n] - data[i]));
}
}

567B Berland National Libray
题意:图书馆进出的时候都要刷卡进去,每个人都有一个ID号。给你一段时间的进出记录,让你算出图书馆的最小容量为多少。

跟模拟几乎相同。注意一下进出时候的容量细节。
代码:

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <functional>
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
#define sf(a) scanf("%d",&a)
#define sff(a,b) scanf("%d%d",&a,&b)
#define sfff(a,b,c) scanf("%d%d%d",&a,&b,&c)
const int INF = 0x7FFFFFFF;
const int MAXN = 1010000;
const double PI = acos(-1.0);
const double esp = 1e-10;
using namespace std;
bool flag[MAXN];
int ans,now;
int main()
{
int n,num;
char c;
sf(n);
while(n--)
{
cin >> c;
sf(num);
if(c=='+')
{
flag[num]++;
now++;
if(now>ans) ans = now;
}
else
{
if(flag[num])
{
flag[num] = 0;
now--;
}
else
{
ans++;
}
}
// cout << ans << endl;
}
printf("%d\n",ans);
return 0;
}

567C. Geometric Progression
题意:有一个三岁的小屁孩特别喜欢三个数组成的等差数列。他如今有一组数,特别想知道里面含多少由三个数组成的等比数列,他年纪太小不会算,想难为一下搞ACM的。

注意 能够不连续,可是等比数列在数组中的位置必须是递增的。
思路:遍历数组,对于每个值都把他当做等比数列的中间的值x,对K求余。余数为零时,看(x/k)在该数之前出现了多少次,(x*k)在该数之后出现了多少次,求和就可以。

如今问题转换成,在x之前 x/k,x*k 出现了多少次?
用map数组处理一下左右的数出现了多少次。在遍历数组的时候。每到一个数mapR[x]--;处理完之后mapL[x]++;具体看代码
代码:

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <functional>
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
#define sf(a) scanf("%d",&a)
#define sff(a,b) scanf("%d%d",&a,&b)
#define sfff(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define lson l,mid,i<<1
#define rson mid+1,r,i<<1|1
#define LL long long
const int INF = 0x7FFFFFFF;
const int MAXN = 1010000;
const double PI = acos(-1.0);
const double esp = 1e-10;
using namespace std;
map<LL,LL> L;
map<LL,LL> R;
LL data[MAXN];
int main()
{
LL n,k;
scanf("%I64d %I64d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%I64d",&data[i]);
R[data[i]]++;
}
LL ans = 0;
for(int i=1;i<=n;i++)
{
R[data[i]]--;
if(data[i]%k==0)
{
ans += L[data[i]/k] * R[data[i]*k];
}
L[data[i]]++;
}
printf("%I64d\n",ans);
return 0;
}

567D. One-Dimensional Battle Ships
题意:又是熟悉的爱丽丝和啵啵。他们在一起玩游戏。简化一下说吧。爱丽丝有K个1*a大小的长方形的木块。不相邻。不相交的放在1~n的方格上。爱丽丝不告诉啵啵他放在了哪里,让啵啵猜。啵啵猜一次。爱丽丝无论啵啵猜中与否。都说“No”,你帮帮啵啵在第几次的时候就能够断定爱丽丝在说谎。问N次无法确定时输出“-1”。
思路:一開始是连续的区间,每猜一次,连续的区间缩小。连续的区间怎么放不下K个小木块都方不下为止,就能够断定她是个小骗子。
我是用set来做的,我想想也能够用线段树来做。用线段树每次来维护区间如今最多还能放下多少下木块,单点更新线段树,可是眼下没能写出来。希望用线段树写出该题的大牛@我,定向您请教。
代码:

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <functional>
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
#define sf(a) scanf("%d",&a)
#define sff(a,b) scanf("%d%d",&a,&b)
#define sfff(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define lson l,mid,i<<1
#define rson mid+1,r,i<<1|1
const int INF = 0x7FFFFFFF;
const int MAXN = 1010000;
const double PI = acos(-1.0);
const double esp = 1e-10;
using namespace std;
struct node
{
int l,r;
}temp;
set<int> S;
set<int> :: iterator it,it1,it2,it3;
int main()
{
int n,k,a,m,num,num1,num2,num3;
sfff(n,k,a);
S.clear();
S.insert(0);
S.insert(n+1);
sf(m);
int aim = (n+1) / (a+1);
// cout << aim << endl;
int i = 0;
int flag = 0;
int Be = 0;
int En = n+1;
while(m--)
{
i++;
sf(num);
S.insert(num);
it = S.find(num);
it--;
it1 = it;
it++;
it2 = it;
it++;
it3 = it;
num1 = *it1;
num2 = *it2;
num3 = *it3;
aim -= (num3 - num1 )/(a+1) -((num3 - num2 )/(a+1) + (num2 - num1 )/(a+1));
// cout<< aim << endl;
if(aim < k)
{
flag = 1;
break;
}
}
if(flag) printf("%d\n",i);
else puts("-1"); }

代码都特别短的~~~~

codeforces Round #Pi (div.2) 567ABCD的更多相关文章

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

随机推荐

  1. POJ1325Machine Schedule(匈牙利算法)

                                                          Machine Schedule Time Limit: 1000MS   Memory L ...

  2. Jenkins获取分支的插件

    Jenkins--->xxxx--->配置--->参数化构建过程--->选择Git Parameter Plug-In插件 Name: git_branch Descripti ...

  3. 显示(explicit )与隐式(implicit)转换操作符

    class Program { static void Main(string[] args) { /* * 不管是显示还是隐式转换,一种类型都只能出现一次 */ Console.WriteLine( ...

  4. leetcode191 Number of 1 Bit

    题意:一个int类型正整数,求它的二进制形式有多少个1 思路:除2递归,可以解出,看了discuss里面有个解更牛,一行结束战斗,是用n&(n-1)再递归,其实并不是很懂怎么想出来这么做的,可 ...

  5. AtCoder - 2705 Yes or No

    Problem Statement You are participating in a quiz with N+M questions and Yes/No answers. It's known ...

  6. 【R笔记】使用R语言进行异常检测

    本文转载自cador<使用R语言进行异常检测> 本文结合R语言,展示了异常检测的案例,主要内容如下: (1)单变量的异常检测 (2)使用LOF(local outlier factor,局 ...

  7. Android介绍

    Android系统的底层建立在Linux系统之上,该平台有操作系统,中间件,用户界面和应用软件4层组成,它采用一种被称为软件叠层(Software Stack)的方式进行构建. 1.应用程序层:And ...

  8. Spring.NET的IoC容器(The IoC container)——简介(Introduction)

    简介 这个章节介绍了Spring Framework的控制反转(Inversion of Control ,IoC)的实现原理. Spring.Core 程序集是Spring.NET的 IoC 容器实 ...

  9. easyui datagrid checkbox的相关属性整理

    DataGrid其中与选择,勾选相关 DataGrid属性: singleSelect boolean 如果为true,则只允许选择一行. false ctrlSelect boolean 在启用多行 ...

  10. android中实现内容搜索

    在编写android搜索代码的时候,怎样去实现搜索功能,考虑中的有两种: 自己定义搜索方法: 1.自己定义搜索输入框,搜索图标,搜索button 2.自己定义语音输入方法 3.自己定义经常使用热词内容 ...