比赛链接:http://hihocoder.com/contest/hihointerview3/problem/1

大概有一个月没怎么打算法了。这一场的前一场BC,也打的不是很好。本来Div1的A和B应该都能AC的,但是A题由于脑子二笔了一下,最后终测T掉了。不过很奇怪,最后分数也没有跌,反而涨了,终于要接近紫名了,下一发不跌的话,应该有紫了。然后说一下这场Hihocoder吧,据说有offer面试名额,然后选了网易游戏和微软,虽然很是想去微软的,但是又二笔了几发,这就这样了。。

A题:九宫(暴力)

http://hihocoder.com/problemset/problem/1268

题目大意就是问原3x3的矩阵能否通过镜像或者旋转得到目标矩阵。

我是写了一个原矩阵和其镜像矩阵,然后分别对这两个矩阵进行旋转来匹配。

当然也可以先搞出所有矩阵,然后进行匹配。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; int to1[][] = {
, , ,
, , ,
, ,
};
int to2[][] = {
, , ,
, , ,
, ,
};
int a[][], ans[][]; bool judge(int x[][])
{
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
if (a[i][j] != && a[i][j] != x[i][j])
return false;
return true;
} void turn(int x[][], int y[][])
{
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
y[][] = x[][];
} void input()
{
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
scanf("%d", &a[i][j]);
} void work()
{
int flag = , to[][];
for (int i = ; i < ; ++i)
{
turn(to1, to);
if (judge(to))
{
flag++;
for (int x = ; x < ; ++x)
for (int y = ; y < ; ++y)
ans[x][y] = to[x][y];
}
for (int x = ; x < ; ++x)
for (int y = ; y < ; ++y)
to1[x][y] = to[x][y];
}
for (int i = ; i < ; ++i)
{
turn(to2, to);
if (judge(to))
{
flag++;
for (int x = ; x < ; ++x)
for (int y = ; y < ; ++y)
ans[x][y] = to[x][y];
}
for (int x = ; x < ; ++x)
for (int y = ; y < ; ++y)
to2[x][y] = to[x][y];
}
if (flag == )
{
for (int x = ; x < ; ++x)
{
for (int y = ; y < ; ++y)
{
if (y) printf(" ");
printf("%d", ans[x][y]);
}
printf("\n");
}
}
else printf("Too Many\n");
} int main()
{
//freopen("test.in", "r", stdin);
input();
work();
return ;
}

B题:优化延迟(二分 && 优先队列)

http://hihocoder.com/problemset/problem/1269

这题二分缓冲区大小,然后对于每一种通过优先队列模拟过程得到最值。

不过我一开始就想好了用cin来输入long long型的,结果最后愣是二笔了一发,叫了一发”%d”。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; const int maxN = ;
int n, p[maxN];
LL Q; LL SP(int k)
{
priority_queue<int> q;
int now = , t = , v;
LL ans = ;
while (now < n || !q.empty())
{
while (q.size() < k && now < n) q.push(p[now++]);
v = q.top();
q.pop();
ans += t*v;
t++;
if (ans > Q) return Q+;
}
return ans;
} bool input()
{
if (!(cin >> n >> Q)) return false;
//if (scanf("%d%d", &n, &Q) == EOF) return false;
for (int i = ; i < n; ++i)
scanf("%d", &p[i]);
return true;
} void work()
{
int lt = , rt = n, mid;
while (lt+ < rt)
{
mid = (lt+rt)>>;
if (SP(mid) <= Q) rt = mid;
else lt = mid;
}
if (SP(lt) <= Q) printf("%d\n", lt);
else if (SP(rt) <= Q) printf("%d\n", rt);
else printf("-1\n");
} int main()
{
//freopen("test.in", "r", stdin);
while (input())
work();
return ;
}

C题:建造基地(动态规划)

http://hihocoder.com/problemset/problem/1270

题目就是对每一层进行一个01背包,然后我二笔的当成普通的动态规划进行分析,然后发现需要线段树优化,然后果断T掉了,然后发现线段树的过程,只需要一个角标判断就搞定了。。最好发现就是个01背包。。这题做的时间太长了,导致最后一题只剩了个读题时间。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; int n, m, k, t;
int a[], b[];
LL p[]; void input()
{
scanf("%d%d%d%d", &n, &m, &k, &t);
for (int i = ; i < m; ++i) scanf("%d", &a[i]);
for (int i = ; i < m; ++i) scanf("%d", &b[i]);
} void work()
{
LL ans = ;
int f;
for (int times = ; times <= n; ++times)
{
memset(p, -, sizeof(p));
p[] = ;
for (int i = ; i < m; ++i)
{
if (b[i] == ) continue;
for (int j = ; j <= k; ++j)
{
f = max(, j-b[i]);
if (p[j] == - || p[j] > p[f]+a[i])
p[j] = p[f]+a[i];
}
}
if (p[k] == -)
{
printf("No Answer\n");
return;
}
ans += p[k];
for (int i = ; i < m; ++i) b[i] /= t;
}
cout << ans << endl;
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
input();
work();
}
return ;
}

D题:舰队游戏

http://hihocoder.com/problemset/problem/1271

首先可以得到的是两个数组正序乘正序 大于 正序乘乱序 大于 正序乘逆序。

所以假设在知道每个舰船的装备栏里面装什么样的飞机的情况下。可以确定每一种飞机的各自归属。

于是只需要2^(m*n)暴力每一个装备栏的飞机种类。然后就可以计算题目要求的了。

ACM学习历程—Hihocoder [Offer收割]编程练习赛1的更多相关文章

  1. hihocoder [Offer收割]编程练习赛4

    描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的人,他希望 ...

  2. hihocoder [Offer收割]编程练习赛61

    [Offer收割]编程练习赛61 A:最小排列 给定一个长度为m的序列b[1..m],再给定一个n,求一个字典序最小的1~n的排列A,使得b是A的子序列. 贪心即可,b是A的子序列,把不在b中的元素, ...

  3. hihocoder offer收割编程练习赛8 C 数组分拆

    思路:(引自bfsoyc的回答:http://hihocoder.com/discuss/question/4160) 动态规划.状态dp[i]表示 前i个数的合法的方案数,转移是 dp[i] = s ...

  4. Hihocoder [Offer收割]编程练习赛70 解题报告 By cellur925

    并没有第四题.(还不会矩阵乘法加速线性数列) 题目1 : 数位翻转 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个数 n,你可以进行若干次操作,每次操作可以翻转 ...

  5. hihocoder [Offer收割]编程练习赛18 C 最美和弦(dp)

    题目链接:http://hihocoder.com/problemset/problem/1532 题解:一道基础的dp,设dp[i][j][k][l]表示处理到第几个数,当前是哪个和弦错了几次初始x ...

  6. hihoCoder [Offer收割]编程练习赛3 D子矩阵求和

    子矩阵求和 http://hihocoder.com/discuss/question/3005 声明一下: n是和x一起的,m是和y一起的 x是横着的,y是纵着的,x往右为正,y往下为正 (非常反常 ...

  7. hihocoder [Offer收割]编程练习赛52 D 部门聚会

    看了题目的讨论才会做的 首先一点,算每条边(u, v)对于n*(n+1)/2种[l, r]组合的贡献 正着算不如反着算 哪些[l, r]的组合没有包含这条边(u, v)呢 这个很好算 只需要统计u这半 ...

  8. hihocoder [Offer收割]编程练习赛14

    A.小Hi和小Ho的礼物 谜之第1题,明明是第1题AC率比C还要低.题目是求在n个不同重量袋子选4袋,2袋给A,2袋给B,使2人获得重量相同,求问方案数. 我也是一脸懵b...o(n2)暴力枚举发现把 ...

  9. hihocoder [Offer收割]编程练习赛8

    第一次做这种比赛,被自己坑的好惨... A.这道题的关键其实是如果有k和n满足kD+F>nL>kD则不能走无限远,分支看似难整理,其实比较简单,F>L根本就不用算了,明摆着就是Bsi ...

随机推荐

  1. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  2. 九度OJ 1192:回文字符串 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3807 解决:1778 题目描述: 给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的. 输入: 输入包括一行字符串 ...

  3. The space of such functions is known as a reproducing kernel Hilbert space.

    Reproducing kernel Hilbert space Mapping the points to a higher dimensional feature space http://www ...

  4. 我的Android进阶之旅------> Android为TextView组件中显示的文本添加背景色

    通过上一篇文章 我的Android进阶之旅------> Android在TextView中显示图片方法 (地址:http://blog.csdn.net/ouyang_peng/article ...

  5. require.js vs browserify

    require.js vs browserify require.js是模块加载器:browserify是预编译工具 require.js遵循的是AMD规范:browserify遵循的是CommonJ ...

  6. Javaweb基础--->监听器listener(转发)

    JavaWeb中的监听器 1.基本概念 JavaWeb中的监听器是Servlet规范中定义的一种特殊类,它用于监听web应用程序中的ServletContext, HttpSession和 Servl ...

  7. 改善程序与设计的55个具体做法 day3

    条款07:为多态基类声明virtual析构函数 任何一本C++语法教材上都会讲这一点(如果没讲,扔掉它),这么做到原因是可以让delete pBase操作能够正确的执行子类的析构函数. 需要说明的是当 ...

  8. js实现select动态添加option

    关于 select 的添加 option 应该注意的问题. 标准的做法如上也就是说,标准的做法是 s.options.add();但是如果你一定要用 s.appendChild(option);注意了 ...

  9. 每天一个Linux命令(19)find命令_初识

    Linux下find命令在目录结构中搜索文件,并执行指定的操作.     (1)用法: 用法: find pathname    -option      [-print | -exec | -ok] ...

  10. CKeditor插件开发流程(一)

    1.放在多文件中 第一步:config.js中 config.extraPlugins = '插件名称';//注册插件,extraPlugins只允许出现一次,你如果之前有新增别的插件,那么用逗号分隔 ...