比赛链接: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. git总是出现untracked content怎么解决?

    git rm --cached vendor/plugins/open_flash_chart_2 rm -rf vendor/plugins/open_flash_chart_2/.git # BA ...

  2. 转载自~浮云比翼:Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)

    Step by Step:Linux C多线程编程入门(基本API及多线程的同步与互斥)   介绍:什么是线程,线程的优点是什么 线程在Unix系统下,通常被称为轻量级的进程,线程虽然不是进程,但却可 ...

  3. Properties类使用

    package com.emolay.util; import java.io.IOException; import java.io.InputStream; import java.util.Pr ...

  4. NEC学习 ---- 布局 -三列,左侧自适应

    效果图: html代码: <div id="demo4"> <div class="g-bd4 f-cb"> <div class ...

  5. 无法启动Mysql服务,错误InnoDB: Attempted to open a previously opened tablespace.

    2013-08-04 13:48:22 760 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous t ...

  6. Avada主题通过自定义CSS全局更换微软雅黑字体

    Avada主题的菜单.正文.标题.面包屑路径等等如果想更换为“微软雅黑”中文字体,只需要进入Avada主题的选项,倒数第二项有个Custom CSS,把下面的代码粘贴进去即可.当然你也可以自行改变字体 ...

  7. freemarker学习

    链接: http://swiftlet.net/archives/category/freemarker

  8. validate 的插件用法

    1.不推荐使用控件方式验证的方式(因为他严重的影响的html代码,也不便于语义化) <input type="text" class="required" ...

  9. js的实参是按值传递还是按引用传递

    1.如果是基本类型,则是按值传递 var str = 'one';function f(string) {    string = 'two';}f(str);console.log(str); // ...

  10. jQuery源代码阅读之三——jQuery实例方法和属性

    jQuery实例方法及属性相关的代码结构如下 jQuery.fn=jQuery.prototype={ jQuery:core_version, constructor:jQuery, selecto ...