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

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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的更多相关文章

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

    比赛链接:http://hihocoder.com/contest/hihointerview27/problems A.Big Plus 模拟水 #include <bits/stdc++.h ...

  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. mongodb在java中的查询

    mongodb 根据_id 查询记录: public Price queryPriceById(String id) throws Exception { return mongoTemplate.f ...

  2. java类初始化顺序

    一.概述 了解类的初始化顺序,可以更灵活.方便的构造一个类. 二.类初始化顺序 2.1 示例 public class InitialOrderTest { public static void ma ...

  3. 浅析java内存模型--JMM(Java Memory Model)

    在并发编程中,多个线程之间采取什么机制进行通信(信息交换),什么机制进行数据的同步? 在Java语言中,采用的是共享内存模型来实现多线程之间的信息交换和数据同步的. 线程之间通过共享程序公共的状态,通 ...

  4. 【原】JAVA SE编码规范

    /* * 编码规范: * 1.所有的命名遵循"见名知意"的原则 * 2.所有的命名不允许使用汉字或拼音 * 3.Java的工程命名建议使用小写,比如:oa.crm.cms... * ...

  5. 学习笔记 MYSQL报错注入(count()、rand()、group by)

    首先看下常见的攻击载荷,如下: select count(*),(floor(rand(0)*2))x from table group by x; 然后对于攻击载荷进行解释, floor(rand( ...

  6. QQ互联登录以及非官方正版应用报100044错误

    QQ第三方登录的时候,显示非官方正版应用,报100044错误:坑1:我们在QQ互联注册成功后需要设置包名和签名,签名是通过官方提供的工具生成的.注意一点:这里的签名是需要由打包签名之后APK生成,我们 ...

  7. c#下volatile关键字

      volatile多用于多线程的环境,当一个变量定义为volatile时,读取这个变量的值时候每次都是从momery里面读取而不是从cache读.这样做是为了保证读取该变量的信息都是最新的,而无论其 ...

  8. Oracle连接odbc数据源

    Oracle连接odbc数据源 说明 oracle连接ODBC数据源有两种方式,hsodbc和dg4odbc,简单说dg4odbc是hsodbc的升级.两种连接方法大致一样,现将连接步骤说明如下: 检 ...

  9. 关于Oracle表连接

    表连接注意left join on与where的区别: select * from dept; select * from emp; select * from emp a right outer j ...

  10. Python 代码风格

    1 原则 在开始讨论Python社区所采用的具体标准或是由其他人推荐的建议之前,考虑一些总体原则非常重要. 请记住可读性标准的目标是提升可读性.这些规则存在的目的就是为了帮助人读写代码,而不是相反. ...