A题:
题目地址: Lineland Mail

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=1e5+10;
struct node
{int id;int value;int Max;int Min;
}q[maxn];
int cmp(struct node a,struct node b)
{return a.value<b.value;
}
int cmp1(struct node a,struct node b)
{return a.id<b.id;
}
int main()
{int n,i;while(~scanf("%d",&n)){for(i=1;i<=n;i++){scanf("%d",&q[i].value);q[i].id=i;q[q[i].id].Max=0;q[q[i].id].Min=0;}sort(q+1,q+n+1,cmp);for(i=1;i<=n;i++){if(i==1){q[i].Min=abs(q[1].value-q[2].value);q[i].Max=abs(q[n].value-q[1].value);}else if(i==n){q[i].Min=abs(q[n].value-q[n-1].value);q[i].Max=abs(q[n].value-q[1].value);}else{q[i].Min=min(abs(q[i].value-q[i-1].value),abs(q[i+1].value-q[i].value));q[i].Max=max(abs(q[i].value-q[1].value),abs(q[n].value-q[i].value));}}sort(q+1,q+1+n,cmp);for(i=1;i<=n;i++){printf("%d %d\n",q[i].Min,q[i].Max);}}return 0;
}

B题:
题目地址:Berland National Library

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=110;
const int maxn1=1e6+10;
char str[10];
int a;
int vis[maxn1];
int main()
{int n;int cnt1,cnt2;while(~scanf("%d",&n)){memset(vis,0,sizeof(vis));cnt1=cnt2=0;for(int i=0;i<n;i++){scanf("%s %d",&str,&a);if(str[0]=='+'){cnt1++;vis[a]=1;cnt2=max(cnt1,cnt2);}else{if(!vis[a]){cnt2++;}else{vis[a]=0;cnt1--;}}}printf("%d\n",cnt2);}return 0;
}

C题:
题目地址:Geometric Progression
题意:求一个序列中形成以k为公比。项数为3的等比数列的种类数。
思路:在这里我用map开了一个dp[i][j]数组,记录长度为i的以j结尾的数字有多少种。所以我们非常easy得出dp[i][j]+=dp[i-1][j/k],dp[1][j]=1。由于我在程序中是用x%k维护的,所以要倒推。由于数据问题map不要开map

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=200010;
LL a[maxn];
int main()
{map<LL,LL> dp[4];int n,k,i;LL ans;while(~scanf("%d %d",&n,&k)){ans=0;for(i=0;i<4;i++)dp[i].clear();for(i=1;i<=n;i++)scanf("%lld",&a[i]);for (i=1;i<=n;i++){if(a[i]%k==0){dp[3][a[i]]+=dp[2][a[i]/k];dp[2][a[i]]+=dp[1][a[i]/k];}dp[1][a[i]]++;}map<LL,LL>::iterator it;for (it=dp[3].begin();it!=dp[3].end();it++)ans+=it->second;printf("%lld\n",ans);}return 0;
}

D题:
题目地址:One-Dimensional Battle Ships
题意:给定一个区间。每次除去一个点,要求在剩下的空白里能放下。k个长为a的区间(a区间不能相离)。

假设能放下,则输出-1。否则的话输出在去处第几个点的时候不能放下。
思路:区间[l,r]每次去除一个点x,则当前剩下的区间为[l,x-1],[x+1,r]。然后找每一个区间能够放下的船数:(区间长度+1)/(船的长度+1){由于船和船之间相离,所以除以的是船的长度+1}。

二分答案去找第几个点让放的船数不足k。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=200010;
int x[maxn];
int x1[maxn];
int n,k,a,m;
int cnt;
int Find(int m)
{for(int i=1;i<=m;i++)x1[i]=x[i];sort(x1+1,x1+m+1);int len=0;cnt=0;for(int i=1;i<=m;i++){cnt+=(x1[i]-len)/(a+1);len=x1[i];}cnt+=(n+1-len)/(a+1);if(cnt>=k)return 1;elsereturn 0;
}
int main()
{scanf("%d %d %d",&n,&k,&a);scanf("%d",&m);for(int i=1;i<=m;i++)scanf("%d",&x[i]);int l=1,r=m;int mid;int res=inf;while(l<=r){mid=(l+r)>>1;if(Find(mid)) l=mid+1;else {r=mid-1;res=min(res,mid);}}//printf("mid==%d\n",mid);//printf("L==%d\n",l);if(l>m)puts("-1");elseprintf("%d\n",res);
}

Codeforces Round #Pi (Div. 2)(A,B,C,D)相关推荐

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

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

  2. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解

    D. One-Dimensional Battle Ships Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

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

    B. Berland National Library Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  4. Codeforces Round #315 (Div. 2)

    题目传送:Codeforces Round #315 (Div. 2) A. Music 题意较难懂.只是仅仅要推公式就好了 注意到S+(q - 1) * t = q * t; 仅仅须要t等于S就可以 ...

  5. [CF]Codeforces Round #529 (Div. 3)

    [CF]Codeforces Round #529 (Div. 3) C. Powers Of Two Description A positive integer xx is called a po ...

  6. Codeforces Round #653 (Div. 3)(A, B, C, D, E1详解)

    Codeforces Round #653 (Div. 3) Required Remainder Thinking(binary search) 既然是找最大值问题,我又懒得去推式子,于是我直接就上 ...

  7. Codeforces Round #717 (Div. 2) D(倍增dp)

    Codeforces Round #717 (Div. 2) D 题意:n个数 q个询问,每一个询问有l和r,问你l到r这段区间中最少能分成几段,每一段中的数都是互质的. 思路:首先预处理出每一个点向 ...

  8. CodeCraft-21 and Codeforces Round #711 (Div. 2) 题解

    先上链接CodeCraft-21 and Codeforces Round #711 (Div. 2) A: 从n开始往后找,不出几十个 一定能找到的,所以暴力就好了 void sovle(){cin ...

  9. Codeforces Round #739 (Div. 3) ABCDEF1F2 解题思路

    Codeforces Round #739 (Div. 3) 可能是一开始大佬都写F1去了,我在D写完后发现F过的人数比E多了好多(个位数与十位数),以为F1比较简单,就直接开F1了,但自己分类讨论老 ...

最新文章

  1. android 请求权限失败怎么办,java – Android HTTP POST请求错误 – 套接字失败EACCES(权限被拒绝)...
  2. 雌性激素过高怎么办?
  3. Java中使用UUID给图片命名的文件上传方法
  4. 高cpu_再一次生产 CPU 高负载排查实践
  5. matlab去趋势,[转载]使用Matlab对数据进行去趋势(detrend)
  6. 不这样做,同名互踢容易踩坑!
  7. SecureCRT SSH 失败 Key exchange failed 解决方法
  8. Linux常用解压文件
  9. 使用WinSCP命令上传文件到CentOS
  10. 【测试面试题每日一刷】22道接口测试面试题,附答案
  11. win7自带的截图工具不能使用的解决办法
  12. HTML5超链接链接ppt可以吗,PPT插入超链接的方法步骤详解
  13. typora 编辑器菜单栏不见了:打开了一体化模式
  14. 真正的爱情是日久生情
  15. UltraVNC源码编译运行
  16. The Sandbox 开启 2022 年新征途,Mega City 土地销售来啦
  17. 2021 年年度最佳开源软件
  18. Python-求一元二次方程ax^2+bx+c=0的解
  19. AI 开发者被疯抢,华为做了什么?
  20. cups共享linux打印机_使用CUPS服务器共享打印机

热门文章

  1. 给Eclipse提速的7个技巧(转)
  2. cnzz统计代码引起的Bad Request - Request Too Long
  3. iOS导航栏标题错乱的解决方法
  4. PostgreSQL学习手册(常用数据类型)
  5. Codeforces 846 A Curriculum Vitae 思维 暴力
  6. 《Arduino实战》——第1章 你好Arduino
  7. PHP MemCached win安装
  8. Mysql安装及入门
  9. 记一次网站部署遇到的问题
  10. ios ---常用的图片处理技术