hihoCoder太阁最新面经算法竞赛18
比赛链接: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的更多相关文章
- Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...
- hihoCoder太阁最新面经算法竞赛15
hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...
- hihocoder Round #c1(hihoCoder太阁最新面经算法竞赛1 )
Test链接:https://cn.vjudge.net/contest/231849 选自hihoCoder太阁最新面经算法竞赛1 更多Test:传送门 A:区间求差 给一组区间集合A和区间集合B, ...
- hihoCoder太阁最新面经算法竞赛19
比赛链接:http://hihocoder.com/contest/hihointerview28/problems A. 固定一个方向,两两相邻的点顺时针或逆时针构造三个向量,判断这个点在这个向量的 ...
- hihoCoder太阁最新面经算法竞赛17
比赛链接:http://hihocoder.com/contest/hihointerview26 A.排序后枚举两个点,确定一个矩形后二分剩下两个点. #include <bits/stdc+ ...
- [HIHO]hihoCoder太阁最新面经算法竞赛7
题目链接:http://hihocoder.com/contest/hihointerview12 期末完事了,终于有时间成套刷题了.这套题比较简单,难度上感觉和上一套差不多.除了最后一个题是看了讨论 ...
- zz 圣诞丨太阁所有的免费算法视频资料整理
首发于 太阁实验室 关注专栏 写文章 圣诞丨太阁所有的免费算法视频资料整理 Ray Cao· 12 小时前 感谢大家一年以来对太阁实验室的支持,我们特地整理了在过去一年中我们所有的原创算法 ...
- [刷题]算法竞赛入门经典 3-12/UVa11809
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa11809:Floating-Point Numbers 代码: //UVa11 ...
- [刷题]算法竞赛入门经典 3-1/UVa1585 3-2/UVa1586 3-3/UVa1225
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO(我也是在网上找到的pdf,但不记得是从哪里搜刮到的了,就重新上传了一遍) PS:第一次写博客分享我的代码,不知道我对c ...
随机推荐
- js中把数据库时间转为正常值
function timeFormatter(value) { var da = new Date(parseInt(value.replace("/Date(", "& ...
- IIS7下的伪静态配置
某个项目是PHP的,本地是Apache + PHP + MYSQL,服务器上的环境是IIS + PHP + MYSQL,开发完成准备部署到服务器上发现伪静态无法使用,原因是IIS不能解析.htacce ...
- 微信H5页面分享
#jssdk.php <?php class JSSDK { private $appId; private $appSecret; public function __construct($a ...
- C#中的特性基本理解
定制特性可以应用的目标元素可以为:程序集(assembly).模块(module).类型(type).属性(property).事件(event).字段(field).方法(method).参数(pa ...
- web页面隐藏鼠标
Java web项目需求需要做一个在页面中,鼠标隐藏,来浏览页面,让客户不能点金页面 重要代码: $('*').css('cursor','none!important'); 示例: <styl ...
- ios开发xcode中设置代码块
在开发中有很多重复的代码,很多开发者把常用的代码做成代码块提高开发效率. 在xcode里选中代码块的时候总是很不容易,点击选中的代码(文字),不要移动和松开鼠标左键,当竖线变成像拉长了的x(我也不知道 ...
- Android 第三方开源下拉框:NiceSpinner
Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框Spinner所提供的设计样式,而改用自定 ...
- [SLAM]2D激光扫描匹配方法
1.Beam Model 2.Likehood field for k=1:size(zt,1) if zt(k,2)>0 d = -grid_dim/2; else d = grid_dim/ ...
- html中表table行循环滚动例子
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><meta h ...
- throttle在程序中的作用
throttle http://www.iciba.com/throttle N-COUNT (汽车.飞机的)节流阀,油门杆,油门踏板 The throttle of a motor vehicle ...