比赛链接:http://hihocoder.com/contest/hihointerview27/problems

A.Big Plus

模拟水

 #include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n;
char G[maxn][maxn]; bool ok(int x, int y) {
return x >= && x < n && y >= && y < n;
}
int check(int x, int y) {
int s = ;
while(ok(x,y-s)&&ok(x,y+s)&&ok(x-s,y)&&ok(x+s,y)&&G[x+s][y]&&G[x-s][y]&&G[x][y+s]&&G[x][y-s]) s++;
return s - ;
} int main() {
// freopen("in", "r", stdin);
memset(G, , sizeof(G));
while(~scanf("%d", &n)) {
for(int i = ; i < n; i++) {
scanf("%s", G[i]);
}
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
G[i][j] -= '';
}
}
int ret = ;
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
if(G[i][j] == ) {
ret = max(ret, check(i, j));
}
}
}
printf("%d\n", ret);
}
return ;
}

B.Interval Coverage

初始的目标是[x,y],结束的目标应当是[y,y]: 因为排好序了的,所以先二分,找到一个区间[l,r],使得r尽可能大,并且l不超过x,找到了这么一个l,位置的下标为pos。 那么,现在就需要在排号序后下标为[1,pos]的r中选择最远的,由于用st表预处理了这个东西,所以直接O(1)可以得到最远的r=t(是值)。 其实就不需要关注这个t对应的那条线段是谁了,反正已经符合条件了,那么就更新x=t就行了,目标变成了[t,y]。讨论区的意思是还有O(n)的解法。

 #include <bits/stdc++.h>
using namespace std; typedef struct Node {
int s, t;
}Node;
const int maxn = ;
int n, x, y;
Node p[maxn]; int dp[maxn][];
int a[maxn], b[maxn]; bool cmp(Node a, Node b) {
if(a.s == b.s) return a.t < b.t;
return a.s < b.s;
} void st() {
for(int i = ; i <= n; i++) dp[i][] = b[i];
int k = int(log(n+1.0)/log(2.0));
for(int j = ; j <= k; j++) {
for(int i = ; i + ( << j) - <= n; i++) {
dp[i][j] = max(dp[i][j-], dp[i+(<<(j-))][j-]);
}
}
} int query(int l, int r) {
int k = int(log(r-l+1.0)/log(2.0));
return max(dp[l][k], dp[r-(<<k)+][k]);
} int bs(int lo, int hi, int x) {
int pos;
while(lo <= hi) {
int mid = (lo + hi) >> ;
if(a[mid] <= x) {
pos = mid;
lo = mid + ;
}
else hi = mid - ;
}
return pos;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d%d%d",&n,&x,&y)) {
for(int i = ; i <= n; i++) {
scanf("%d%d",&p[i].s,&p[i].t);
}
sort(p+, p+n+, cmp);
for(int i = ; i <= n; i++) {
a[i] = p[i].s;
b[i] = p[i].t;
}
st();
int ret = ;
bool flag = ;
while(x < y) {
int pos = bs(, n, x);
int t = query(, pos);
if(x == t) {
flag = ;
break;
}
x = t;
ret++;
}
if(flag) puts("-1");
else printf("%d\n", ret);
}
return ;
}

C.Split Array

题意仅仅是要求分成的小数组里有且仅有k个数字并且连续。那么从头到尾扫一边,每一次都提出一个数字就行了。

 #include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n, m, k, a;
int cnt[maxn]; int main() {
// freopen("in", "r", stdin);
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d",&n,&k);
memset(cnt, , sizeof(cnt));
m = ;
for(int i = ; i <= n; i++) {
scanf("%d", &a);
cnt[a]++;
m = max(m, a);
}
bool flag = ;
for(int i = ; i <= m; i++) {
if(flag == ) break;
if(cnt[i] > ) {
while(cnt[i] > ) {
for(int j = i; j < i + k; j++) {
if(cnt[j] > ) cnt[j]--;
else {
flag = ;
break;
}
}
}
}
}
if(flag) puts("NO");
else puts("YES");
}
return ;
}

hihoCoder太阁最新面经算法竞赛18的更多相关文章

  1. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

  2. hihoCoder太阁最新面经算法竞赛15

    hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...

  3. hihocoder Round #c1(hihoCoder太阁最新面经算法竞赛1 )

    Test链接:https://cn.vjudge.net/contest/231849 选自hihoCoder太阁最新面经算法竞赛1 更多Test:传送门 A:区间求差 给一组区间集合A和区间集合B, ...

  4. hihoCoder太阁最新面经算法竞赛19

    比赛链接:http://hihocoder.com/contest/hihointerview28/problems A. 固定一个方向,两两相邻的点顺时针或逆时针构造三个向量,判断这个点在这个向量的 ...

  5. hihoCoder太阁最新面经算法竞赛17

    比赛链接:http://hihocoder.com/contest/hihointerview26 A.排序后枚举两个点,确定一个矩形后二分剩下两个点. #include <bits/stdc+ ...

  6. [HIHO]hihoCoder太阁最新面经算法竞赛7

    题目链接:http://hihocoder.com/contest/hihointerview12 期末完事了,终于有时间成套刷题了.这套题比较简单,难度上感觉和上一套差不多.除了最后一个题是看了讨论 ...

  7. zz 圣诞丨太阁所有的免费算法视频资料整理

    首发于 太阁实验室 关注专栏   写文章     圣诞丨太阁所有的免费算法视频资料整理 Ray Cao· 12 小时前 感谢大家一年以来对太阁实验室的支持,我们特地整理了在过去一年中我们所有的原创算法 ...

  8. [刷题]算法竞赛入门经典 3-12/UVa11809

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa11809:Floating-Point Numbers 代码: //UVa11 ...

  9. [刷题]算法竞赛入门经典 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO(我也是在网上找到的pdf,但不记得是从哪里搜刮到的了,就重新上传了一遍) PS:第一次写博客分享我的代码,不知道我对c ...

随机推荐

  1. VS 调试

    Vs 单步调试 在vs中的单步调试: 调试重要的几个键: F9在当前光标所在的行下断点,如果当前行已经有断点,则取消断点. F5调试状态运行程序,程序执行到有断点的地方会停下来. F10单步执行程序. ...

  2. TypeScript学习记录

    TypeScript官网 TypeScript中文网 TypeScrpit Handbook 中文版 DefinitelyTyped The TypeScript Definition Manager ...

  3. 使用 readfile() 下载文件

    下载图片 <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Tran ...

  4. Decimal To Fraction 小数转换成分数

    以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. //小数转分数 //0.3 -> 3/10, 0.2 ...

  5. H5页面实现一个Audio标签加载多个音频文件,并进行播放和展示音频长度

    最近微信项目中有需求,要将微信端发送过来的amr格式的语音文件,在项目中的页面上进行展示和播放,实现方式如下: 1.首先java后台收到微信端的消息推送的时候,使用 ffmpeg将amr格式的音频文件 ...

  6. 复制代理JOB

    复制代理说明: 复制代理执行许多与复制有关的任务,其中包括创建架构和数据副本.检测发布服务器或订阅服务器上的更新以及在服务器之间传播更改. 默认情况下,复制代理在 Microsoft SQL Serv ...

  7. yum下载rpm

    yum下载rpm yum update --downloadonly --downloaddir=/root/rpm_package/   python-pip

  8. PRML读书笔记——Mathematical notation

    x, a vector, and all vectors are assumed to be column vectors. M, denote matrices. xT, a row vcetor, ...

  9. 【转】SQL Server中关于跟踪(Trace)那点事

    前言 一提到跟踪俩字,很多人想到警匪片中的场景,同样在我们的SQL Server数据库中“跟踪”也是无处不在的,如果我们利用好了跟踪技巧,就可以针对某些特定的场景做定向分析,找出充足的证据来破案. 简 ...

  10. svg学习(一)

    SVG 是使用 XML 来描述二维图形和绘图程序的语言. 什么是SVG? SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用来定义用于网络的基于矢量的图形 SV ...