A题

1.新添加一间酒店,要求酒店离已有的最近的一间酒店的距离恰好等于d

2.最左和最右必定存在合适的两种情况

3.酒店之间的情况就要判断两间酒店间的距离:

小于2d,表示无法在这两间酒店中间找到合适情况
等于2d,表示这两间酒店的正中间可以满足条件,新建酒店
大于2d,表示这两间酒店之间存在两种满足条件的情况

 #include<bits/stdc++.h>

 /*

 -6 0 5 6 12 13 19

 2 6 10 13 16 21
*/
using namespace std;
#define int long long
#define N 209
map<int,int> mp;
int arr[N];
signed main(){
int n,d;
cin>>n>>d;
for(int i=;i<=n;i++)
{
cin>>arr[i];
mp[arr[i]]=;
}
if(n==){
cout<<;
return ;
}
sort(arr+,arr++n);
int sum=;
for(int i=;i<=n;i++){
if(i==){
if(!mp[arr[i]+d]&&(arr[i+]-(arr[i]+d))>=d){
mp[arr[i]+d]=;
// cout<<arr[i]+d<<endl;
sum++;
}
continue;
}
if(i==n){
if(!mp[arr[i]-d]&&(arr[i]-d-arr[i-])>=d){
mp[arr[i]-d]=;
// cout<<arr[i]-d<<endl;
sum++;
}
continue;
}
if(!mp[arr[i]-d]&&(arr[i]-d-arr[i-])>=d){
mp[arr[i]-d]=;
// cout<<arr[i]-d<<endl;
sum++;
}
if(!mp[arr[i]+d]&&(arr[i+]-(arr[i]+d))>=d){
mp[arr[i]+d]=;
// cout<<arr[i]+d<<endl;
sum++;
}
}
printf("%d\n",sum+);
return ;
} /*
3 2
4 4
5 6
6 9
*/ */

B题

题意:有一排n个格子,每个格子里能放一种花,一共有两种花,一种用 0 代表,另一种用 1 代表,然后给你m各区间,每个区间的价值就是这个区间内的两种花的数量之积。问你应该怎么放花,使得这些区间的价值和最大。

思路:就是说让0 1 的个数在各个区间内都是接近的(和相等,越接近,积越大),也就是说0 1 分布均匀,那么,我们直接0 1 交替输出,就可以保证0 1 在各个区间都是最接近的。

AC代码:

#include<bits/stdc++.h>

using namespace std;
#define N 200505
struct str{
int l,r;
int cha;
}st[N];
int main(){
int n,m;
cin>>n>>m;
for(int i=;i<=m;i++){
cin>>st[i].l>>st[i].r; }
for(int i=;i<=n;i++){
if(i%)
cout<<;
else
cout<<;
} return ;
}
/*
2 1
3 2
4 4
5 6
6 9
101010
2+4+2 101010
1+4+2
*/ /**/

C题:

题意:给出一个长为n的数列(数字可以重复),表示在i号位置的数字为ai。.现在,在数列的最左和最右端有一个报数机器人,最左端的机器人向右移动,最右端的机器人向左移动,每移动到一个位置时,机器人就会将这个位置的数字报出来。现在,每个机器人都有一个编号,如果机器人报出来的数字和这个编号相同的话,机器人就会停止移动。
问,这两个机器人的编号有多少种情况,可以使这两个机器人不发生碰撞。
思路:跑后缀就行。用MAP标记超时了QAQ
AC代码:
 #include<map>
#include<stdio.h>
#include<iostream>
#include<algorithm> using namespace std; #define int long long
#define N 250000
int arr[N];
int sum[N];
int mp[N];
int mmp[N];
signed main(){
int n;
cin>>n;
for(int i=;i<=n;i++)
scanf("%lld",&arr[i]);
int add=; for(int i=n;i>=;i--){
sum[i]=add;
if(!mmp[arr[i]])
add++;
mmp[arr[i]]=;
}
int ans=;
for(int i=;i<=n;i++){
if(mp[arr[i]])
continue;
ans+=sum[i];
mp[arr[i]]=;
}
cout<<ans;
return ;
}

Codeforces Round #495 (Div. 2) A,B,C的更多相关文章

  1. Codeforces Round #495 (Div. 2) D. Sonya and Matrix

    http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...

  2. Codeforces Round #495 (Div. 2) C. Sonya and Robots

    http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...

  3. Codeforces Round #495 (Div. 2) B

    题目链接:http://codeforces.com/contest/1004/problem/B B. Sonya and Exhibition time limit per test 1 seco ...

  4. Codeforces Round #495 (Div. 2) Sonya and Matrix

    正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. 06 ServletConfig、ServletContext_作用域对象

    ServletConfig:表示servlet的配置信息,一个servlet对象对应一个servletconfig对象   方法: 1.获取初始化参数 config.getInitParameter( ...

  2. 2019杭电多校一 A. Blank (dp)

    大意: 长为$n$的数组, 每个位置范围$[0,3]$, $m$个限制$(l,r,x)$表示$[l,r]$内有$x$种数, 求方案数. 维护每个数字最后一次出现位置, 暴力$DP$ 实现时有个技巧是把 ...

  3. Luogu4081 USACO17DEC Standing Out from the Herd(广义后缀自动机)

    建出广义SAM,通过parent树对每个节点求出其是否仅被一个子串包含及被哪个包含. 写了无数个sam板子题一点意思都没啊 #include<bits/stdc++.h> using na ...

  4. Tomcat与WAS应用中间件差异化分析研究

    --转载 http://blog.chinaunix.net/uid-25723371-id-5759072.html 目前我们在使用的基于JAVA的提供逻辑展现应用中间件有两种,一种是以商用软件WA ...

  5. (四)Spring Boot之配置文件-多环境配置

    一.Properties多环境配置 1. application.properties配置激活选项 spring.profiles.active=dev 2.添加其他配置文件 3.结果 applica ...

  6. Html5+Mui前端框架,开发记录(一)

    1.下载HBuilder X,地址:http://www.dcloud.io/hbuilderx.html,根据需求选择版本下载. Mui文档,地址:http://dev.dcloud.net.cn/ ...

  7. MVC5项目转.Net Core 2.2学习与填坑记录(1)

    流程都是自己摸索,错误地方随便指正... 老项目过于臃肿,并且所有请求都是提交到一个api中,这样当api挂掉的时候,基本所有的项目都瘫痪掉了. 在4月底的时候,下决心将项目用微服务进行重写,刚开始的 ...

  8. tint2

    #---------------------------------------------# TINT2 CONFIG FILE#---------------------------------- ...

  9. sql 批量插入

    create  PROCEDURE insertinto as begindeclare @id int;set @id=1;while @id<10begininsert into perso ...

  10. PHP 根据二维数组中的某个字段进行排序

    <?php $data = array( array( 'id' => 5698, 'first_name' => 'Bill', 'last_name' => 'Gates' ...