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 & ...
随机推荐
- Zabbix使用点滴
Application --> Items --> Triggers 1.磁盘柜日志输出至Rsyslog服务器,Zabbix抓取:System-Syslogsystem-log(log[/ ...
- IBatis存储过程返回值
<parameterMaps> <parameterMap id="delVersionBagInfoParam" class="DelVersionB ...
- 线程GCD
#import "ViewController.h" @interfaceViewController () @end @implementation ViewController ...
- logo新
- linux REDHAT6.4下安装ArcGIS Server 10.1
1 安装环境 因为Linux的发行版本比较多,我们在使用的时候请严格按照官网给的给出的版本,在官网上给出的是经过严格测试的,如果采用其他的,即便安装上了,在后续的运作中出现问题,这个可就麻烦了,官网对 ...
- Ubuntu一路填坑...
1.安装 从ubuntu9.0开始,一路更新,越来越垃圾,更可恶的是工作上经常指定特定的版本,于是乎,我电脑里装了n个版本的ubuntu. Win7 + Ubuntu 15.10 1)装完win7之后 ...
- arguments 对象的老历史
引题:为什么 JavaScript 中的 arguments 对象不是数组 http://www.zhihu.com/question/50803453 JavaScript 1.0 1995 年, ...
- JS自动缩放页面图片
/** * 缩略图 * * @param bool isScaling 是否缩放 * @param int width 宽度 * @param int height 高度 * @param strin ...
- ASP.NET Core--授权过滤器
翻译如下: 目前,我们正在从事这方面工作. 我们欢迎您的加入,以帮助塑造范围和方法.您可以跟踪状态并在此提供的输入问题在GitHub上. 如果你想查看初稿并在此主题的大纲,请留下注意到在您的联系信息的 ...
- SoapUI 设置 request data with json body
--背景 使用WCF定义REST风格的WebService,如下: [ServiceContract] public interface INISTService { [Op ...