2019DX#5
| Solved | Pro.ID | Title | Ratio(Accepted / Submitted) |
| 1001 | fraction 辗转相除 | 4.17%(7/168) | |
| ok | 1002 | three arrays 字典树+贪心 | 12.69%(76/599) |
| 1003 | geometric problem | 1.59%(1/63) | |
![]() |
1004 | equation | 20.65%(310/1501) |
![]() |
1005 | permutation 1 | 24.77%(407/1643) |
![]() |
1006 | string matching | 23.12%(724/3131) |
![]() |
1007 | permutation 2 | 47.19%(688/1458) |
| ok | 1008 | line symmetric 计算几何 | 1.87%(11/588) |
| 1009 | discrete logarithm problem 离散对数 | 18.42%(7/38) | |
| 1010 | find hidden array 贪心 | 6.25%(2/32) |
1002 three arrays
题意
给定两个长度为1e5的数组$a_1,a_2,...a_n$、$b_1,b_2,...b_n$,重新排列,使得$a_i \oplus b_i $的字典序最小。
$0 \le a_i , b_i < 2^{30}$
思路
对a数组和b数组建立两个字典树,然后遍历n次这两个字典树,每次两个指针分别从两颗字典树移动,能同时向0走就走,能同时向1走就向1走,每次走到底层后就是一个答案。
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int maxn = 1e5+;
int a[maxn],b[maxn];
int tot[],rt[];
int bz[];
struct node{
int ch[];
int fa;
int sz;
void init(int f) {
ch[] = ch[] = ;
fa = f;
sz = ;
}
}tree[][maxn * ];
int shu[]; void add(int p, int len, int flag) {
if(len == ){
tree[flag][p].sz++;
return;
} if(tree[flag][p].ch[shu[len]] == )
{
tree[flag][p].ch[shu[len]] = ++ tot[flag];
tree[flag][tot[flag]].init(p);
}
int nx = tree[flag][p].ch[shu[len]];
add(nx, len-, flag);
int lc = tree[flag][p].ch[];
int rc = tree[flag][p].ch[];
tree[flag][p].sz = tree[flag][lc].sz + tree[flag][rc].sz;
}
void insert(int val, int flag) {
int len = ;
for(int i=; i<=; i++) shu[++len] = val % , val /= ;
add(rt[flag], , flag);
}
void display(int rt, int flag) {
if(rt == ) return ;
// cout<<tree[flag][rt].sz<<endl;
display(tree[flag][rt].ch[], flag);
display(tree[flag][rt].ch[], flag);
}
vector<int>vec;
void find(int a, int b, int cen, int val) {
if(cen == ) {
vec.pb(val);
tree[][a].sz--;
tree[][b].sz--;
return;
}
if(tree[][ tree[][a].ch[] ].sz && tree[][ tree[][b].ch[]].sz ) {
find(tree[][a].ch[], tree[][b].ch[], cen-, val);
}
else if(tree[][ tree[][a].ch[] ].sz && tree[][ tree[][b].ch[]].sz) {
find(tree[][a].ch[], tree[][b].ch[], cen-, val);
}
else if(tree[][tree[][a].ch[]].sz && tree[][ tree[][b].ch[]].sz){
find(tree[][a].ch[], tree[][b].ch[], cen-, val + bz[cen-]);
}
else {
find(tree[][a].ch[], tree[][b].ch[], cen-, val + bz[cen-]);
} tree[][a].sz = tree[][tree[][a].ch[]].sz + tree[][tree[][a].ch[]].sz;
tree[][b].sz = tree[][tree[][b].ch[]].sz + tree[][tree[][b].ch[]].sz; }
int main(){
int T; scanf("%d", &T);
bz[] = ;
for(int i=; i<=; i++) bz[i] = * bz[i-];
while(T--) {
tot[] = tot[] = ;
rt[] = ++tot[];
tree[][rt[]].init();
rt[] = ++tot[];
tree[][rt[]].init(); int n; scanf("%d", &n);
for(int i=; i<=n; i++) scanf("%d", &a[i]), insert(a[i], );
for(int i=; i<=n; i++) scanf("%d", &b[i]), insert(b[i], ); vec.clear();
for(int i=; i<=n; i++) {
find(rt[], rt[], , );
}
sort(vec.begin(), vec.end());
for(int i=; i<vec.size() - ; i++) printf("%d ", vec[i]);
printf("%d\n", vec[vec.size() - ]);
// display(rt[0], 0);
}
return ;
}
1008 line symmetric
题意
给定一个多边形,定点最多有1000个,在最多移动一个点的情况下,此多边形是否能成为轴对称图形,变换后图形要保证是简单多边形。
思路
1)枚举相邻点,和间隔为2的两个点,令他们的中垂线为对称轴,判断是否可行。
2)注意点是,一个点如果在枚举的对称轴上,那么就是不可行的。
3)如果两个点如果在对称轴的两边,且要相互交换位子,那么这也是不可行的。
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int maxn = 1e3+;
pii po[maxn];
int n;
bool dc(int le, int ri, pii m, pii k){
// 判垂直
int a = (po[ri].se - po[le].se) * k.se;
int b = (po[ri].fi - po[le].fi) * k.fi;
if(a != -b) return false; // 判中点
pii mid;
mid.fi = (po[le].fi + po[ri].fi) / ;
mid.se = (po[le].se + po[ri].se) / ; if(k.fi == ) {
return mid.fi == m.fi;
}
a = mid.se * k.fi;
b = k.se * mid.fi + m.se * k.fi - k.se * m.fi;
return a == b;
} bool gao(int p1, int p2, pii m, pii k) {
if(k.fi == ) {
return (po[p1].fi - m.fi) * (po[p2].fi - m.fi) <= ;
}
int tmp1 = po[p1].se * k.fi - k.se * po[p1].fi + m.se * k.fi- k.se * m.fi;
int tmp2 = po[p2].se * k.fi - k.se * po[p2].fi + m.se * k.fi- k.se * m.fi;
return 1ll*tmp1 * tmp2 <= ;
}
bool check(int le, int ri) {
int sl = le, sr = ri;
pii m, k; m.fi = (po[le].fi + po[ri].fi) / ;
m.se = (po[le].se + po[ri].se) / ;
k.fi = po[ri].se - po[le].se;
k.se = -*(po[ri].fi - po[le].fi);
int cnt = ; for(int i=; i <= (n+) / ; i++){
if(gao(sl, le, m, k) && gao(sr, ri, m, k) ) return false;
if(dc(le, ri, m, k) == ) cnt++; ri++; if(ri == n+) ri = ;
le--; if(le == ) le = n;
}
return cnt <= ;
} bool check1(int le, int ri, int mid) {
int sl = le, sr = ri;
pii m, k;
m.fi = (po[le].fi + po[ri].fi) / ;
m.se = (po[le].se + po[ri].se) / ;
k.fi = po[ri].se - po[le].se;
k.se = -*(po[ri].fi - po[le].fi);
// cout<<m.fi<<" , " << m.se<<endl;
// cout<<k.fi<<" , " << k.se<<endl;
int cnt = ;
for(int i=; i <= n / ; i++){
if(gao(sl, le, m, k) && gao(sr, ri, m, k)) return false;
if(dc(le, ri, m, k) == ) cnt++; ri++; if(ri == n+) ri = ;
le--; if(le == ) le = n;
} if(dc(mid, mid, m, k) == ) cnt++;
return cnt <= ;
}
int main(){
int T; scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i=; i<=n; i++) {
scanf("%d%d", &po[i].fi, &po[i].se);
po[i].fi *= ;
po[i].se *= ;
}
if(n <= ) {
puts("Y");
continue;
}
int flag = ; for(int i=; i<=n; i++) {
int nx = (i + ) ; if(nx == n+) nx = ;
int la = i - ; if(!la) la = n;
int mid = i;
if(check1(la,nx, mid)) flag = ;
}
for(int i=; i<=n; i++) {
int cur = i;
int nx = i + ; if(nx == n+) nx = ;
if(check(cur, nx)) flag = ;
} if(flag) puts("Y");
else puts("N");
}
return ;
}
/*
5
-100 -100
0 0
-100 100
1 0
100 1
*/
2019DX#5的更多相关文章
- 2019DX#10
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Minimum Spanning Trees 22.22%(2/9) 1002 Lin ...
- 2019dx#9
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Rikka with Quicksort 25.85%(38/147) 1002 Ri ...
- 2019DX#8
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Acesrc and Cube Hypernet 7.32%(3/41) 1002 A ...
- 2019dx#7
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 A + B = C 10.48%(301/2872) 1002 Bracket Seq ...
- 2019DX#6
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Salty Fish 16.28%(7/43) OK 1002 Nonsense Tim ...
- 2019dx#4
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 AND Minimum Spanning Tree 31.75%(1018/3206) ...
- 2019DX#3
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Azshara's deep sea 凸包 6.67%(6/90)
- 2019DX#2
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Another Chess Problem 8.33%(1/12) 1002 Beau ...
- 2019DX#1
1001 Blank 题意 有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个.问颜色个数的方案数. 思路 DP 四维的DP,利用滚动数组优化一维空 ...
随机推荐
- SpringBoot Kafka 整合使用
前提 假设你了解过 SpringBoot 和 Kafka. 1.SpringBoot 如果对 SpringBoot 不了解的话,建议去看看 DD 大佬 和 纯洁的微笑 的系列博客. 2.Kafka K ...
- 在 alpine 中使用 NPOI
在 alpine 中使用 NPOI Intro 在 .net 中常使用 NPOI 来做 Excel 的导入导出,NPOI 从 2.4.0 版本开始支持 .netstandard2.0,对于.net c ...
- 【算法】【查找】二分法 Bisection
#include<stdio.h> int main(){ ,,,,,,,,,,,,,,}; ; //长度 ; //要查找到的值 int Bisection(int x,int* a,in ...
- [Spring cloud 一步步实现广告系统] 14. 全量索引代码实现
上一节我们实现了索引基本操作的类以及索引缓存工具类,本小节我们开始实现加载全量索引数据,在加载全量索引数据之前,我们需要先将数据库中的表数据导出到一份文件中.Let's code. 1.首先定义一个常 ...
- springmvc原理详解(手写springmvc)
最近在复习框架 在快看小说网搜了写资料 和原理 今天总结一下 希望能加深点映像 不足之处请大家指出 我就不画流程图了 直接通过代码来了解springmvc的运行机制和原理 回想用springmvc用 ...
- 带你剖析WebGis的世界奥秘----瓦片式加载地图
WebGIS应用程序的页面能够通过HTML.JSP.ASP或任何任何类型的Web页文件构成,其特殊之处在于,它的请求提交的方法并不是通过常用的 "超链接"形式,而是使用鼠标与Web ...
- .netcore持续集成测试篇之测试方法改造
系列目录 通过前面两节讲解,我们的测试类中已经有两个测试方法了,总体上如下 public class mvc20 { private readonly HttpClient _client; publ ...
- Javarscipt中数组或者字符串的随机排序方法
在日常开发中,经常会遇到随机排序的需求,思路就是利用Math.random()方法,抽取随机数,让数组中的元素进行对调: 话不多说直接上代码,方法一:基本思路就是将a中随机抽取一个元素,放入b中,再从 ...
- 记录一次Git解决CONFLICT冲突
目录 记录一次Git解决CONFLICT冲突 1.CONFLICT产生的原因 2.Git正确的LIANGZHONG 使用流程 2.1 暂存,拉取,恢复暂存,合并(如果有冲突),提交,推送 2.2 将本 ...
- Oracle 主键、联合主键的查询与创建
--查询某个表是否有唯一主键 select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = ...
