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 ...
随机推荐
- java中动态代理的实现
动态代理的实现 使用的模式:代理模式. 代理模式的作用是:为其他对象提供一种代理以控制对这个对象的访问.类似租房的中介. 两种动态代理: (1)jdk动态代理,jdk动态代理是由Java内部的反射机制 ...
- C标准头文件<math.h>
定义域错误可以理解为超出了函数的适用范围,如果发生了定义域错误,设errno为EDOM 如果结果不能表示为double值,则发生值域错误,如果结果上溢,则函数返回HUGE_VAL的值,设errno为E ...
- Java名字的由来
Java语言的历程丰富多彩,被现在众多程序员和企业广泛使用,不用质疑这是Java的领先技术的结果. Java是Sun公司开发的一种编程语言,Sun公司最初的方向是让Java来开发一些电器装置程序,如: ...
- (转) Qt 出现“undefined reference to `vtable for”原因总结
由于Qt本身实现的机制所限,我们在使用Qt制作某些软件程序的时候,会遇到各种各样这样那样的问题,而且很多是很难,或者根本找不到原因的,即使解决了问题,如果有人问你为什么,你只能回答--不知道. 今天我 ...
- RESTful Api 身份认证安全性设计
REST是一种软件架构风格.RESTful Api 是基于 HTTP 协议的 Api,是无状态传输.它的核心是将所有的 Api 都理解为一个网络资源.将所有的客户端和服务器的状态转移(动作)封装到 H ...
- iOS从零开始学习直播之音频2.后台播放和在线播放
本篇主要讲音频的后台播放和在线播放. 后台播放 上一篇写的工程运行之后程序退至后台,发现运行不了,歌停止了,这显然不行,音乐后台播放是标配啊.今天就来讲一下后台播放. 1.在plist文件里,告诉 ...
- 【代码笔记】iOS-用户发布后能保存崩溃
一,工程图. 二,代码. AppDelegate.m #import "AppDelegate.h" #import "RootViewController.h" ...
- win7的6个网络命令
1 名称: Ipconfig 参数: /all : 显示详细信息 /renew: 更新所有适配器 /renew EL*:更新所有名称以EL为开头的连接 /release *Con*: 释放所有匹配的连 ...
- 简单配置 nginx 反向代理
# Nginx 域名反向代理配置# 安装nginx yum install nginx -y# 修改配置文件 进入配置文件目录 cd /etc/nginx/conf.d 新建配置文件以.conf结尾 ...
- 萌新笔记——Cardinality Estimation算法学习(一)(了解基数计算的基本概念及回顾求字符串中不重复元素的个数的问题)
最近在菜鸟教程上自学redis.看到Redis HyperLogLog的时候,对"基数"以及其它一些没接触过(或者是忘了)的东西产生了好奇. 于是就去搜了"HyperLo ...