2015ACM/ICPC亚洲区长春站
5532 Almost Sorted Array
题目大意:给你一个序列,如果它拿掉其中一个数后,可以是该序列成为非递减或非递增序列,则输出YES。
有两种思路,第一种代码比较简单,是LIS,复杂度nlogn,第二种是On的复杂度。
LIS的代码如下。
#include <set>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
#define mem(x,y) memset(x, y, sizeof(x))
#define lson l,m,rt << 1
#define rson m+1,r,rt << 1 | 1
const int INF = 0x3f3f3f3f;
;
int s[maxn], dp[maxn];
int T, n;
bool judge()
{
mem(dp, INF);
; i < n; i++)
{
*upper_bound(dp, dp + n, s[i]) = s[i];
}
int len = lower_bound(dp, dp + n, INF) - dp;
mem(dp, INF);
; i < n; i++)
{
*upper_bound(dp, dp + n, -s[i]) = -s[i];
}
int len2 = lower_bound(dp, dp + n, INF) - dp;
len = max(len2, len);
);
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d", &n);
; i < n; i++)
{
scanf("%d", s+i);
}
printf("%s\n", judge() ? "YES" : "NO");
}
;
}
5533 Dancing Stars on Me题意:给你n个点对,然后求一个正多边形(当然是凸的)。问存不存在。
题目给的坐标都是整数,看一看那个tanα = 1 / n (n = 1, 2, 3, 4,....)好像只有α = 45°的时候才有可能构成正多边形。
然后瞎搞搞。。
#include <cstdio>
#include <algorithm>
using namespace std;
;
int T, n;
];
struct ss{int x, y;}s[maxn];
int get_dis(int x1, int y1, int x2, int y2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
; i < n; i++)
{
scanf("%d%d", &s[i].x, &s[i].y);
}
) {printf("NO\n");continue;}
, tot = ;
; i < n; i++)
{
; j < n; j++)
{
temp[tot] = get_dis(s[i].x, s[i].y, s[j].x, s[j].y);
tot++;
}
}
sort(temp, temp + tot);
] == temp[]) ok = ;
printf("%s\n", ok ? "YES" : "NO");
}
;
}
5536 Chip Factory
题意:在数组a中找到三个数满足,ai+aj ^ ak 的值最大且i,j,k各不相同。
经典的异或用01字典树,推荐使用数组形式,快而且内存小。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
+ ;
* maxn;
int n, T;
LL a[maxn];
LL sz, ch[maxnode][], val[maxnode];
void init()
{
sz = ;
memset(ch[], , ]));
}
//d=1表示插入,d=-1表示删除
void trie_update(LL x, int d)
{
;
; i >= ; i--)
{
;
if(!ch[u][c])
{
memset(ch[sz], , sizeof(ch[sz]));
val[sz] = ;
ch[u][c] = sz++;
}
u = ch[u][c];
val[u] += d;
}
}
LL trie_query(LL v)
{
LL ans = ;
;
; i >= ; i--)
{
;
] && val[ch[u][c ^ ]])
{
ans |= ( << i);
u = ch[u][c ^ ];
}
else u = ch[u][c];
}
return ans;
}
int main()
{
scanf("%d", &T);
while(T--)
{
init();
scanf("%d", &n);
; i < n; i++)
{
scanf("%I64dd", a + i);
trie_update(a[i], );
}
LL ans = (a[] + a[]) ^ a[];
; i < n; i++)
{
trie_update(a[i], -);
; j < n; j++)
{
trie_update(a[j], -);
LL temp = trie_query((LL)a[i] + a[j]);
ans = max(ans, temp);
trie_update(a[j], );
}
trie_update(a[i], );
}
printf("%I64d\n", ans);
}
;
}
5538 House Building
题意:求这个东西的表面积。
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, T;
#define judge(x, y) 0 <= x && x < n && 0 <= y && y < m
][];
, , -, };
, -, , };
int main()
{
scanf("%d", &T);
while(T--)
{
, bottom = , cnt = ;
scanf("%d%d", &n, &m);
; i < n; i++)
{
; j < m; j++)
{
scanf("%d", &ma[i][j]);
tot += ma[i][j];
if(ma[i][j]) bottom++;
) cnt += (ma[i][j] - ) * ;
}
}
* tot - bottom - cnt;
;
; i < n; i++)
{
; j < m; j++)
{
; k < ; k++)
{
int fx = i + dx[k];
int fy = j + dy[k];
if(judge(fx, fy))
{
d += min(ma[fx][fy], ma[i][j]);
}
}
}
}
ans -= d;
printf("%d\n", ans);
}
;
}
2015ACM/ICPC亚洲区长春站的更多相关文章
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU-5532//2015ACM/ICPC亚洲区长春站-重现赛-F - Almost Sorted Array/,哈哈,水一把区域赛的题~~
F - Almost Sorted Array Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
随机推荐
- IE8的parseInt
踩到一个IE8的parseInt的坑: Chrome:
- android 手机去哪儿7.2版本客户端 账号存储信息分析
1.data/data/com.qunar sharepref 文件夹下的Qunarperferences.xml文件中 username,phone等均为加密处理过字段 2.jdgui下查找关键 ...
- Node.js入门笔记(4):文件系统(fs)
文件系统(FileSystem) 文件系统模块 对于文件无外乎创建修改添加. File System - 文件系统模块 - require('fs') fs模块是核心模块,需要使用require导入后 ...
- EXPLAINING WHAT ACTION AND FUNC ARE
http://simpleprogrammer.com/2010/09/24/explaining-what-action-and-func-are/ Explaining What Action A ...
- JVM Management API
JVM本身提供了一组管理的API,通过该API,我们可以获取得到JVM内部主要运行信息,包括内存各代的数据.JVM当前所有线程及其栈相关信 息等等.各种JDK自带的剖析工具,包括jps.jstack. ...
- Redis、Memcache和MongoDB的区别(转)
1.性能 都比较高,性能对我们来说应该都不是瓶颈 总体来讲,TPS方面redis和memcache差不多,要大于mongodb 2.操作的便利性 memcache数据结构单一 redis丰富一些,数据 ...
- 【Bootstrap】Bootstrap-select多选下拉框实现
目录 前言 需要引用的它们 核心选项 核心方法 实例应用 回到顶部 前言 项目中要实现多选,就想到用插件,选择了bootstrap-select. 附上官网api链接,http://silviomor ...
- OC中的extern,static,const
const的作用: const仅仅用来修饰右边的变量(基本数据变量p,指针变量*p). 被const修饰的变量是只读的. static的作用: 修饰局部变量: 1.延长局部变量的生命周期,程序结束才会 ...
- java表格的使用 单元格绘制二
JTable单元格是由单元格绘制器绘制出来的,这是一些执行TableCellRenderer接口的类.TableCellRenderer接口定义了唯一的getTableCellRendererComp ...
- URL、URN、URI的区别?
URL.URN.URI区别 既然Web应用程序的文件等资源是放在服务器上,而服务器是因特网(Internet)上的主机,当然必须要有个方法,告诉浏览器到哪里取得文件等资源.通常会听到有人这么说:“你要 ...