Hihocoder 太阁最新面经算法竞赛18
Hihocoder 太阁最新面经算法竞赛18
source: https://hihocoder.com/contest/hihointerview27/problems
题目1 : Big Plus
描述
Given an NxN 01 matrix, find the biggest plus (+) consisting of 1s in the matrix.
size 1 plus size 2 plus size 3 plus size 4 plus
1 1 1 1
111 1 1 1
1 11111 1 1
1 1111111 1
1 1 111111111
1 1
1 1
1
1
输入
The first line contains an integer N. (1 <= N <= 500)
Then follow an NxN 01 matrix.
输出
The size of the biggest plus in the matrix.
- 样例输入5
-
00100
00100
11111
00110
10101 - 样例输出 2
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAXN = 505; int n, ans;
char mp[MAXN][MAXN];
int U[MAXN][MAXN], D[MAXN][MAXN], LEF[MAXN][MAXN], RIG[MAXN][MAXN]; int main(){
int tmp;
while(scanf("%d", &n) != EOF){
for(int i=1; i<=n; ++i){
getchar();
for(int j=1; j<=n; ++j){
scanf("%c", &mp[i][j]);
}
}
memset(U, 0, sizeof(U)); memset(D, 0, sizeof(D));
memset(LEF, 0, sizeof(LEF)); memset(RIG, 0, sizeof(RIG));
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j){
if(mp[i][j] == '1'){
U[i][j] = U[i-1][j] + 1;
LEF[i][j] = LEF[i][j-1] + 1;
}
}
}
for(int i=n; i>=1; --i){
for(int j=n; j>=1; --j){
if(mp[i][j] == '1'){
D[i][j] = D[i+1][j] + 1;
RIG[i][j] = RIG[i][j+1] + 1;
}
}
}
ans = 0;
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j){
if(mp[i][j] == '1'){
tmp = min(min(U[i][j], RIG[i][j]), min(D[i][j], LEF[i][j]));
if(tmp-1 > ans){
ans = tmp - 1;
}
}
}
}
printf("%d\n", ans );
}
return 0;
}
题目2 : Interval Coverage
描述
You are given N intervals [S1, T1], [S2, T2], [S3, T3], ... [SN, TN] and a range [X, Y]. Select minimum number of intervals to cover range [X, Y].
输入
The first line contains 3 integers N, X and Y. (1 <= N <= 100000, 1 <= X < Y <= 1000000)
The following N lines each contain 2 integers Si, Ti denoting an interval. (1 <= Si < Ti <= 1000000)
输出
Output the minimum number of intevals to cover range [X, Y] or -1 if it is impossible.
- 样例输入
-
5 1 5
1 2
1 3
2 4
3 5
4 5 - 样例输出
-
2
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAXN = 100000 + 5;
struct Interval{
int s, t;
}inte[MAXN];
int n, x, y; int cmp(const void *a, const void *b){
Interval *aa = (Interval *)a;
Interval *bb = (Interval *)b;
if(aa->s == bb->s){
return aa->t - bb->t;
}
return aa->s - bb->s;
}
int main(){
freopen("in.txt", "r", stdin); int ans, far, start;
while(scanf("%d %d %d", &n, &x, &y) != EOF){
for(int i=0; i<n; ++i){
scanf("%d %d", &inte[i].s, &inte[i].t);
}
qsort(inte, n, sizeof(inte[0]), cmp);
if(inte[0].s > x){
ans = -1;
}else{
far = max(x, inte[0].t);
start = x;
ans = 1;
for(int i=0; i<n; ++i){
if(far >= y){
break;
}
if(inte[i].s <= start){
far = max(far, inte[i].t);
}else if(inte[i].s > far){
break;
}else{
start = far;
far = max(far, inte[i].t);
++ans;
}
}
if(far < y){
ans = -1;
}
}
printf("%d\n", ans );
}
return 0;
}
题目3 : Split Array
描述
You are given an sorted integer array A and an integer K. Can you split A into several sub-arrays that each sub-array has exactly K continuous increasing integers.
For example you can split {1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6} into {1, 2, 3}, {1, 2, 3}, {3, 4, 5}, {4, 5, 6}.
输入
The first line contains an integer T denoting the number of test cases. (1 <= T <= 5)
Each test case takes 2 lines. The first line contains an integer N denoting the size of array A and an integer K. (1 <= N <= 50000, 1 <= K <= N)
The second line contains N integers denoting array A. (1 <= Ai <= 100000)
输出
For each test case output YES or NO in a separate line.
- 样例输入
-
2
12 3
1 1 2 2 3 3 3 4 4 5 5 6
12 4
1 1 2 2 3 3 3 4 4 5 5 6 - 样例输出
-
YES
NO
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int MAXN = 50000 + 5;
const int MAXV = 100000 + 5; int n, k, num[MAXV];
int main(){
freopen("in.txt", "r", stdin); int test_case, val, maxval, tmp, flag;
scanf("%d", &test_case); while(test_case--){
scanf("%d %d", &n, &k);
maxval = 0;
memset(num, 0, sizeof(num));
for(int i=0; i<n; ++i){
scanf("%d", &val);
num[val]++;
maxval = max(maxval, val);
}
flag = 1;
for(int i=1; i<=maxval; ++i){
if(num[i] > 0){
tmp = num[i];
for(int j=0; j<k; ++j){
num[i+j] -= tmp;
}
}else if(num[i] < 0){
flag = 0;
break;
}
}
if(flag){
printf("YES\n");
}else{
printf("NO\n");
}
}
return 0;
}
Hihocoder 太阁最新面经算法竞赛18的更多相关文章
- hihoCoder太阁最新面经算法竞赛18
比赛链接:http://hihocoder.com/contest/hihointerview27/problems A.Big Plus 模拟水 #include <bits/stdc++.h ...
- 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 ...
随机推荐
- scikit-learn一般实例之四:管道的使用:链接一个主成分分析和Logistic回归
主成分分析(PCA)进行无监督的降维,而逻辑回归进行预测. 我们使用GridSearchCV来设置PCA的维度 # coding:utf-8 from pylab import * import nu ...
- 使用图片视频展示插件blueimp Gallery改造网站的视频图片展示
在很多情况下,我们网站可能会展示我们的产品图片.以及教程视频等内容,结合一个比较好的图片.视频展示插件,能够使得我们的站点更加方便使用,也更加酷炫,在Github上有很多相关的处理插件可以找来使用,有 ...
- enote笔记法使用范例(1)——自己总结的一些编写代码的常识 (a)
章节. 编程习惯 why 函数(<<为了>>便于提升软件开发效率和维护效率) 开发角度: 1)隐藏实现细节,这也是API质量最重要的品质2)复用:通过使用函数来代码复用 ...
- 使用PhantomJS实现网页截图服务
这是上半年遇到的一个小需求,想实现网页的抓取,并保存为图片.研究了不少工具,效果都不理想,不是显示太差了(Canvas.Html2Image.Cobra),就是性能不怎么样(如SWT的Brower). ...
- ECharts的简单使用过程
网页中经常要使用图表,以前使用的是highcharts插件,现在发现echarts使用起来和highcharts差不多,但是个人感觉echarts更酷炫,以下是echarts的使用过程,其实highc ...
- GJM : Unity3D 高通Vuforia SDK AR 开发
一.AR概念: 增强现实(Augmented Reality,简称AR),是在虚拟现实的基础上发展起来的新技术,也被称之为混合现实.是通过计算机系统提供的信息增加用户对现实世界感知的技术,将虚拟的信息 ...
- autofac 组件的实例范围
实例范围决定如何在请求之间共享服务. 原文地址:http://docs.autofac.org/en/latest/lifetime/instance-scope.html 每个依赖一个实例 使用这个 ...
- Struts2框架深入详解版
一.认识Struts2 1. 什么是Web框架? 1.1 模型1 1.2 模型2 和MVC 1.3 Web框架的诞生 2. Struts1 到Struts2 2.1 其他 Web框架 2.2 ...
- Drupal 8.2.4安装简体中文步骤
安装的时候发现很多情况下会出现各种问题,现在写下自己安装成功的步骤: 1.首先官网下载zip安装包drupal-8.2.4.zip 2.下载官方提供的8.2.4简体中文语言包drupal-8.2.4. ...
- 一个成功的BI项目实施需要注意哪些?
BI是所有IT系统中最适合于管理层和决策层使用的信息系统. ERP等各类信息系统中的数据,只有通过BI才能将隐藏在数据中的信息挖掘出来.转化为事实. BI的实施也需要依据企业情况进行“定制”.如何实施 ...