链接:http://acm.hust.edu.cn/vjudge/contest/view.action?

cid=62515#overview

描写叙述:第三场CF训练了。这次做的挺搞笑的,我记得这是内天持续训练九个小时中的最后两个小时,想想也是蛮拼的。

题解:

A.

cid=62515#problem/A" style="color:blue; text-decoration:none; font-family:Verdana; font-size:14.44444465637207px; line-height:20px; background-color:rgb(226,228,255)">Triangle

题意:给四个边。假设能组成推断能不能从当中找三条边组成三角形,不就再推断能不能三条边首尾相接组成一个线段。

思路:三角形推断条件,两条边之和大于第三条边。两边之和等于第三条边就是线段。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int main()
{
int a[5];
for(int i=0;i<4;i++)
scanf("%d",&a[i]);
sort(a,a+4);
if(a[0]+a[1]>a[2]||a[1]+a[2]>a[3])
puts("TRIANGLE");
else if(a[0]+a[1]==a[2]||a[1]+a[2]==a[3]||a[0]+a[2]==a[3])
puts("SEGMENT");
else puts("IMPOSSIBLE");
return 0;
}

B.

cid=62515#problem/B" style="color:blue; text-decoration:none; font-family:Verdana; font-size:14.44444465637207px; line-height:20px">Alice, Bob and Chocolate

题意:两个人,一个从左边開始吃巧克力,一个右边開始吃巧克力。两个人吃的速度是一样的。假设两人同一时候開始吃同一块巧克力,右边人放弃。问两边人各吃多少个巧克力。

思路:记每一个个每一个巧克力吃的时间。比一下即可。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int main()
{
int tot;
scanf("%d",&tot);
int aa[100005];
int l[100005],r[100005];
int sum = 0;
l[0]=0;
for(int i=0;i<tot;i++)
{
scanf("%d",&aa[i]);
}
for(int i=1;i<tot;i++)
l[i]=l[i-1]+aa[i-1];
r[tot-1]=0;
for(int i=tot-2;i>=0;i--)
r[i]=r[i+1]+aa[i+1];
int Alice = 0,Bob = 0;
for(int i=0;i<tot;i++)
{
if(l[i]<=r[i])
Alice++;
else Bob++;
}
cout<<Alice<<" "<<Bob<<endl;
}

C.President's
Office

题意:给一个n*m的图,里面用大写字母表示桌子,找到和给出的字母相邻的字母的种类数之和。

思路:对于每一个存在的字母找一下上,下,左,右就可以。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
char ss[105][105];
bool vis[60];
int main()
{
int row,col;
char cap[5];
scanf("%d%d%s",&row,&col,cap);
for(int i=0;i<row;i++)
scanf("%s",ss[i]);
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(ss[i][j]==cap[0])
{
if(i>0)
if(ss[i-1][j]!=cap[0]&&ss[i-1][j]>='A')
vis[ss[i-1][j]-'A']=1;
if(j>0)
if(ss[i][j-1]!=cap[0]&&ss[i][j-1]>='A')
vis[ss[i][j-1]-'A']=1;
if(i<row)
if(ss[i+1][j]!=cap[0]&&ss[i+1][j]>='A')
vis[ss[i+1][j]-'A']=1;
if(j<col)
if(ss[i][j+1]!=cap[0]&&ss[i][j+1]>='A')
vis[ss[i][j+1]-'A']=1;
}
}
}
int ans = 0;
for(int i=0;i<26;i++)
if(vis[i])
ans++;
printf("%d\n",ans);
return 0;
}

D.Longest Regular Bracket Sequence

题意:给一个长的字符串,当中都是"("和")",问最长的合理括号匹配子串是多长。而且找出该长度的子串有多少个。

思路:比赛的时候,了。

是写DP搞了好久都搞不出来,加上脑子糊里糊涂的。就GG了。思路是这种,对于每一个")",假设它左边的是合理的匹配,而且找到它左边的合理匹配的第一个"("的左端也是"(",那么它的匹配数是左边的匹配数+2,即dp[i]=dp[i-1]+2,而且假设找到的合理匹配的左端还存在合理匹配,那么它的合理匹配长度还要加上前面合理匹配的长度。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 10005
#define PI acos(-1.0)
#define seed 31//131,1313
#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int dp[1000005];
char ss[1000005];
int main()
{
int i , time = 1,ans = 0;
scanf("%s",ss);
memset(dp,0,sizeof(dp));
for(i=1; ss[i]!='\0'; i++)
{
if(i-dp[i-1]-1>=0&&ss[i]==')'&&ss[i-dp[i-1]-1]=='(')
{
dp[i]=dp[i-1]+2;
if(i-dp[i-1]-2>=0)
dp[i]+=dp[i-dp[i-1]-2];
}
if(dp[i]>ans)
{
ans = dp[i];
time = 1;
}
else if(dp[i]==ans&&ans!=0)
{
time++;
}
}
printf("%d %d\n",ans,time);
}

E.

cid=62515#problem/E" style="color:blue; text-decoration:none; font-family:Verdana; font-size:14.44444465637207px; line-height:20px; background-color:rgb(226,228,255)">Exposition

题意:给出N本书,n<=10^5,这n本书按出版时间给出的,给出了每本书的高度hi。而且给出一个k。k<=10^6,要求在n本书选择当中连续的若干本书。当中最高的高度比最高的高度不能大于k,问最多能够选择多少本书。

思路:二分+RMQ。

从左至右依次选择每本书作为起点,二分来选择符合条件的终点来保证以该本书为起点的长度最长,对于每次的终点,找到起点终点之间的最高高度和最低高度。假设符合条件,那么终点右移,否则终点左移。查询最高高度和最低高度的方式是ST表,O(NlogN)的预处理,然后O(1)的查询,二分的过程中的复杂度也是O(NlogN)。

代码:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-8
#define INF 0x7fffffff
#define maxn 100005
#define PI acos(-1.0)
#define seed 31//131,1313
#define LOCAL
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int stTable_min[maxn][32],stTable_max[maxn][32];
int preLog2[maxn];
int h[maxn];
int Left[maxn],Right[maxn];
int ans = 0,times = 0;
void st_prepare(int n,int *array)
{
preLog2[1]=0;
for(int i=2; i<=n; i++)
{
preLog2[i]=preLog2[i-1];
if((1<<preLog2[i]+1)==i)
preLog2[i]++;
}
for(int i=n-1; i>=0; i--)
{
stTable_min[i][0]=array[i];
stTable_max[i][0]=array[i];
for(int j=1; (i+(1<<j)-1)<n; j++)
{
stTable_min[i][j]=min(stTable_min[i][j-1],stTable_min[i+(1<<j-1)][j-1]);
stTable_max[i][j]=max(stTable_max[i][j-1],stTable_max[i+(1<<j-1)][j-1]);
}
}
return ;
}
int query_sub(int l,int r)
{
int len=r-l+1,k=preLog2[len];
return max(stTable_max[l][k],stTable_max[r-(1<<k)+1][k])-min(stTable_min[l][k],stTable_min[r-(1<<k)+1][k]);
}
int main()
{
int all = 0;
int tot,k;
scanf("%d%d",&tot,&k);
for(int i=0;i<tot;i++)
scanf("%d",&h[i]);
st_prepare(tot,h);
for(int i=0;i<tot;i++)
{
int l = i , r = tot;
while(r>l+1)
{
int mid = (l + r) / 2;
if(query_sub(i,mid)>k)
r=mid;
else l=mid;
}
if(l-i+1>ans)
{
ans=l-i+1;
times=1;
Left[0]=i;
Right[0]=l;
}
else if(l-i+1==ans)
{
Left[times]=i;
Right[times++]=l;
}
}
printf("%d %d\n",ans,times);
for(int i=0;i<times;i++)
printf("%d %d\n",Left[i]+1,Right[i]+1);
return 0;
}

CUGBACM Codeforces Tranning 3 题解的更多相关文章

  1. CUGBACM Codeforces Tranning 1 题解

    链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61581#overview 描写叙述:非常老的CF题,题不错,拿来训练正好. 做的时 ...

  2. Codeforces Round #556 题解

    Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...

  3. Codeforces Round #569 题解

    Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...

  4. Codeforces Round #557 题解【更完了】

    Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...

  5. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  6. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  7. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  8. Codeforces Choosing Laptop 题解

    这题实在是太水了,具体看注释 蒟蒻的方法是一边找过时的电脑一边比大小 蒟蒻不才,只会C++ 其实还会free basic,但它已经过时了 附: 本题洛谷网址 Codeforces网址 希望蒟蒻的题解能 ...

  9. Codeforces 381 简要题解

    做的太糟糕了...第一题看成两人都取最优策略,写了个n^2的dp,还好pre-test良心(感觉TC和CF的pretest还是很靠谱的),让我反复过不去,仔细看题原来是取两边最大的啊!!!前30分钟就 ...

随机推荐

  1. 飞天KEY

    RoyCShell.exe -PE -if:"G:\EncryptTool\Finder.exe" -of:"G:\EncryptTool\Finder_enc.exe& ...

  2. web.xml加载顺序 [转载]

    一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...

  3. api的mock开源工具;api文档生成器;api的mock工具;阿里系;其他开源

    django-rest-framework,即drf的api文档,包括自带的文档和其他三方文档,比如swagger.DRF Docs等 https://www.django-rest-framewor ...

  4. SPSS19.0实战之多元线性回归

    线性回归数据来自于国泰安数据服务中心的经济研究数据库.网址:http://www.gtarsc.com/p/sq/.数据名称为:全国各地区能源消耗量与产量,该数据的年度标识为2006年,地区包括我国3 ...

  5. OpenMP 线程同步之临界区

    多核/多线程编程中肯定会用到同步互斥操作.除了互斥变量以为,就是临界区. 临界区是指在用一时刻只允许一个线程执行的一段用{...},包围的代码段. 在OpenMP中临界区声明方法如下: #pragma ...

  6. go语言基础之基匿名函数本语法和闭包

    一.匿名函数 示例1: package main import "fmt" func main() { a := 10 str := "mike" //匿名函数 ...

  7. 监听内容变化 TextWatcher @功能

    监听多个TextView的内容变化 使用示例 TextWatcherUtils.addTextChangedListener(isAllNotEmpty -> btnLogin.setEnabl ...

  8. 前端如何接收 websocket 发送过来的实时数据

    WebSocket protocol 是HTML5一种新的协议,它实现了浏览器与服务器全双工通信(full-duple).刚开始的握手需要借助HTTP请求完成,在 WebSocket API,浏览器和 ...

  9. by,with

    一.表示使用有形的工具时,通常用with来表示.例如: 用钢笔写 write with a pen 用肉眼看 see with naked eyes 用锤子敲打 strike with a hamme ...

  10. 使用百度地图API实现轨迹回放

    调用百度地图API实现路线的轨迹回放功能其实很简单,只要搞懂以下几点即可: 1.需要用Polyline方法先绘制好路线图 2.用Marker添加标注点 3.关键一步,通过结合定时器,使用Marker创 ...