hihoCoder太阁最新面经算法竞赛17
比赛链接:http://hihocoder.com/contest/hihointerview26
A.排序后枚举两个点,确定一个矩形后二分剩下两个点。
#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = ;
typedef struct Point {
int x, y;
Point() {}
Point(int xx, int yy) : x(xx), y(yy) {}
}Point;
int n;
LL ans;
Point p[maxn]; bool cmp(Point a, Point b) {
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
} bool bs(int x, int y) {
int ll = , rr = n, mm;
while(ll <= rr) {
mm = (ll + rr) >> ;
if(p[mm].x == x && p[mm].y == y) return ;
else if(cmp(p[mm], Point(x, y))) ll = mm + ;
else rr = mm - ; }
return ;
} int main() {
// freopen("in", "r", stdin);
int x3, y3, x4, y4;
while(~scanf("%d", &n) && n) {
ans = 1000000LL * 1001000LL;
for(int i = ; i < n; i++) {
scanf("%d%d", &p[i].x, &p[i].y);
}
sort(p, p+n, cmp);
for(int i = ; i < n; i++) {
for(int j = i + ; j < n; j++) {
x3 = p[i].x; y3 = p[j].y;
x4 = p[j].x; y4 = p[i].y;
if(bs(x3, y3) && bs(x4, y4)) {
int a = x3 - x4;
int b = y3 - y4;
if((LL)a * b == ) continue;
ans = min(ans, abs((LL)a*b));
}
}
}
printf("%lld\n", ans == 1000000LL * 1001000LL ? - : ans);
}
return ;
}
B.按题要求爆搜
#include <bits/stdc++.h>
using namespace std; const int maxn = ;
int n;
set<string> ret;
set<string>::iterator it;
int num[maxn];
set<int> pos; int main() {
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
for(int i = ; i < maxn; i++) num[i] = i;
while(~scanf("%d", &n)) {
ret.clear();
do {
int nn = ( << (n));
for(int i = ; i < nn; i++) {
pos.clear();
int tmp = i;
int cnt = ;
while(tmp) {
if(tmp & ) pos.insert(cnt+);
tmp >>= ; cnt++;
}
string t = "";
bool ex = ;
t += (num[] + '');
int pre = num[];
for(int i = ; i <= n; i++) {
if(ex) break;
if(pos.find(i) != pos.end()) {
t += '-';
pre = -;
}
if(pre > num[i]) {
ex = ;
break;
}
t += (num[i] + '');
pre = num[i];
}
if(!ex) ret.insert(t);
}
// for(int i = 1; i <= n; i++) printf("%d", num[i]);
// printf("\n");
}while(next_permutation(num+, num+n+));
// printf("%d\n", ret.size());
for(it = ret.begin(); it != ret.end(); it++) {
cout << *it << endl;
}
}
return ;
}
C.找到规律后斯特灵数胡搞(好像没必要?)
#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const int maxn = ;
const LL mod = 1000000007LL;
LL f[maxn], a[maxn];
LL S[maxn][maxn];
int n; LL exgcd(LL a, LL b, LL &x, LL &y) {
if(b == ) {
x = ;
y = ;
return a;
}
else {
LL ret = exgcd(b, a%b, x, y);
LL tmp = x;
x = y;
y = tmp - a / b * y;
return ret;
}
} LL inv(LL a) {
LL x, y;
exgcd(a, mod, x, y);
return (x % mod + mod) % mod;
} LL C(LL n, LL m) {
return f[n] * inv(f[m]) % mod * inv(f[n-m]) % mod;
} LL mul(LL x, LL n) {
LL ret = ;
while(n) {
if(n & ) ret = ret * x % mod;
n >>= ;
x = x * x % mod;
}
return ret;
} int main() {
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
memset(S, , sizeof(S));
S[][] = ;
for(int p = ; p < maxn; p++) {
for(int k = ; k < maxn; k++) {
S[p][k] = (LL)k * S[p-][k] % mod + S[p-][k-] % mod;
}
}
f[] = ;
for(int i = ; i < maxn; i++) {
f[i] = f[i-] * (LL)i % mod;
}
memset(a, , sizeof(a));
a[] = ; a[] = ;
for(int i = ; i <= ; i++) {
for(int k = ; k <= i; k++) {
a[i] = (a[i] + f[k] * S[i][k] % mod) % mod;
}
}
while(~scanf("%d", &n)) {
printf("%lld\n", a[n]);
}
return ;
}
hihoCoder太阁最新面经算法竞赛17的更多相关文章
- 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太阁最新面经算法竞赛18
比赛链接:http://hihocoder.com/contest/hihointerview27/problems A.Big Plus 模拟水 #include <bits/stdc++.h ...
- [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 ...
随机推荐
- yii2添加自定义字段
在模型model文件中,添加 public $attributes;即可,$attributes 为要添加的新字段
- 实施费用也能DIY--走出软件作坊:三五个人十来条枪 如何成为开发正规军(九)[转]
上次咱们讲完了开发费用的计算,很多人在后面跟帖在那里算费用. 有人说:你把程序员都不当人,94天,一天都不休息啊. 我想答曰:94天,是工作时间.不算双休日在里面.也就是说,实际的开发周期长度是94+ ...
- 使用git和github托管个人项目
1. 安装 cygwin 和 cygwin 下的 git , 测试 git 命令可用; 参考: https://cygwin.com/install.html 2. 注册 github 账号: ...
- scala构建类似java的pojo
主要看以下代码: package com.test.scalaw.test.demo import scala.beans.BeanProperty /** * scala构建类似java 的pojo ...
- api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案
api-ms-win-crt-runtime就是MFC的运行时环境的库, 在windows上编译也是用微软的visual studio C++编译的软件, 底层也会用到微软提供的C++库和runtim ...
- HTML5与移动端Web
概述 HTML5 提供了很多新的功能,主要有: 新的 HTML 元素,例如 section, nav, header, footer, article 等 用于绘画的 Canvas 元素 用于多媒体播 ...
- mysql的sql文件的备份与还原
1.备份 $mysqldump –u root –p*** dbname > filename.sql 2.还原 前提是数据库必须存在 $mysql –u root –p*** dbname ...
- JS 动态加载脚本 执行回调_转
关于在javascript里面加载其它的js文件的问题可能很多人都遇到过,但很多朋友可能并不知道怎么判断我们要加载的js文件是否加载完成,如果没有加载完成我们就调用文件里面的函数是不会成功的.本文讲解 ...
- StringUtils中 isEmpty 和isBlank的区别
StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出Nu ...
- ubuntu12.04下安卓编译环境搭建总结
前言: 因为工作需要,经常要编译安卓下的动态库,公司有已经搭建好环境的服务器,但是第一自己想自己搭建一下了解一个整个过程,另外,公司的服务器也经常出现问 题,导致编译不了,所以就想自己搭建环 ...