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 ...
随机推荐
- How to change Jenkins default folder on Windows?
http://stackoverflow.com/questions/12689139/how-to-change-jenkins-default-folder-on-windows accepted ...
- struts2 笔记03 异常支持、防止页面刷新和后退、方法验证
Struts2对异常支持(声明式异常.自动的异常处理), 异常处理(运行期异常事务自动回滚) 1. 自定义异常类,继承RuntimeException或Exception实现构造方法. 2. 配置异常 ...
- java笔试题: ——将e:/source文件夹下的文件打个zip包后拷贝到f:/文件夹下面
将e:/source文件夹下的文件打个zip包后拷贝到f:/文件夹下面 import java.io.*; import java.util.zip.ZipEntry; import java.uti ...
- css分离思想
CSS命名就应该最简单.最直接,直捣黄龙.没有HTML标签,没有层级,这些通通滚蛋,不要.为什么不要,有三大原因: 1. 限制重用 我们会使用层级(#test .test),会使用标签(ul.test ...
- blade模版之页面的嵌套
blade模版 相关关键词:@section @yield @extends @extends @show @parent(追加内容而不是覆盖) 父页面view\layout\f.blade.php ...
- HTTP详解(1)-工作原理【转】
转自:http://blog.csdn.net/hguisu/article/details/8680808 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 1 HTTP简 ...
- Linux程序存储结构与进程结构堆和栈的区别【转】
转自:http://www.hongkevip.com/caozuoxitong/Unix_Linux/24581.html 红客VIP(http://www.hongkevip.com):Linux ...
- Android使用Application总结
对于application的使用,一般是 在Android源码中对他的描述是; * Base class for those who need to maintain global applicati ...
- org.hibernate.MappingException: Unknown entity常见问题。回顾笔记,以前没记,现在补上,xiaochao写的蛮好的直接给转载了。
转自http://www.blogjava.net/xiaochao/articles/hibernatetopic.html. 官方说明如下: Hibernate遵循EJB3.0实体bean的注解规 ...
- Android内存溢出解决方案(OOM)
众所周知,每个Android应用程序在运行时都有一定的内存限制,限制大小一般为16MB或24MB(视平台而定).因此在开发应用时需要特别关注自身的内存使用量,而一般最耗内存量的资源,一般是图片.音频文 ...