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 ...
随机推荐
- dota玩家与英雄契合度的计算器,python语言scrapy爬虫的使用
首发:个人博客,更新&纠错&回复 演示地址在这里,代码在这里. 一个dota玩家与英雄契合度的计算器(查看效果),包括两部分代码: 1.python的scrapy爬虫,总体思路是pag ...
- JVM复习笔记
1. JVM是什么? JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来 ...
- 慎用MySQL replace语句
语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [PARTITION (partition_name,...)] [(col_name,... ...
- USB 设备类协议入门【转】
本文转载自:http://www.cnblogs.com/xidongs/archive/2011/09/26/2191616.html 一.应用场合 USB HID类是比较大的一个类,HID类设备属 ...
- 在Ubuntu Kylin下安装QQ教程
下载: 下载地址:http://www.ubuntukylin.com/application/show.php?lang=cn&id=279 下载后解压得到wine-qqintl文件夹,里面 ...
- fprintf 读入%s,要注意
eg 文件内容faninfd 14 "%s %d",会把整行内容放到%s 而%d是乱码 ps: 文件内容是 1,2,3 “%d,%d,%d” 文件内容是1:2:3 ...
- VS 6.00 工程项目文件详解
*.dsp(DeveloperStudio Project):是VC++的工程配置文件,比如说你的工程包含哪个文件,你的编译选项是什么等等,编译的时候是按照.dsp的配置来的.*.dsw(Develo ...
- Oracle性能优化--DBMS_PROFILER
想看到过程或者函数执行每一步的过程:想看到每一步所占的时间吗?借助profiler吧:它可以满足你来分析过程/函数执行比较久:可以直接快速找到病因:从而可以优化那一步需要优化下. 一 ...
- Quick-cocos2d-x v3.3 SocketTCP链接(转)
Quick-Cocos2d-x v3.3里面提供了两种长连接WebSockets.SocketTCP,这里说一下SocketTCP的用法. 1 2 3 local net = require(&quo ...
- 错误Mybatis 元素类型为 "resultMap" 的内容必须匹配 "(constructor?,id*,result*,association*,collection*,discriminat
今天算是见识了什么事顺序的重要性. 在使用mybatis时由于联合了其他的表,用到了resultMap,之后外加association这一项.可是在替换对应字段的位置上加上association总是报 ...