2018-2019 ACM-ICPC, Asia Seoul Regional Contest
ProblemA Circuits
Solved.
题意:
有$n$个矩形,可以放两条平行与$x$轴的线,求怎么放置两条无线长的平行于$x$轴的线,使得他们与矩形相交个数最多
如果一个矩形同时与两条线相交,只算一次。
思路:
离散化后枚举一根线,另一根线用线段树维护,扫描线思想
#include <bits/stdc++.h>
using namespace std; #define N 400010
int n;
int b[N];
int x[N], y[N];
vector <int> in[N], out[N];
int ans[N]; namespace SEG
{
struct node
{
int Max, lazy;
node () {}
node (int Max, int lazy) : Max(Max), lazy(lazy) {}
void init() { Max = lazy = ; }
void add(int x)
{
Max += x;
lazy += x;
}
node operator + (const node &other) const
{
node res; res.init();
res.Max = max(Max, other.Max);
return res;
}
}a[N << ];
void build(int id, int l, int r)
{
a[id].init();
if (l == r)
return;
int mid = (l + r) >> ;
build(id << , l, mid);
build(id << | , mid + , r);
}
void pushdown(int id)
{
if (!a[id].lazy) return;
a[id << ].add(a[id].lazy);
a[id << | ].add(a[id].lazy);
a[id].lazy = ;
}
void update(int id, int l, int r, int ql, int qr, int x)
{
if (l >= ql && r <= qr)
{
a[id].add(x);
return;
}
int mid = (l + r) >> ;
pushdown(id);
if (ql <= mid) update(id << , l, mid, ql, qr, x);
if (qr > mid) update(id << | , mid + , r, ql, qr, x);
a[id] = a[id << ] + a[id << | ];
}
int query(int id, int l, int r, int pos)
{
if (l == r) return a[id].Max;
int mid = (l + r) >> ;
pushdown(id);
if (pos <= mid) return query(id << , l, mid, pos);
else return query(id << | , mid + , r, pos);
}
} void Hash()
{
sort(b + , b + + b[]);
b[] = unique(b + , b + + b[]) - b - ;
for (int i = ; i <= n; ++i) x[i] = lower_bound(b + , b + + b[], x[i]) - b;
for (int i = ; i <= n; ++i) y[i] = lower_bound(b + , b + + b[], y[i]) - b;
} int main()
{
while (scanf("%d", &n) != EOF)
{
b[] = ;
for (int i = ; i < N; ++i)
in[i].clear(), out[i].clear();
for (int i = , tmp; i <= n; ++i)
{
scanf("%d%d%d%d", &tmp, y + i, &tmp, x + i);
// cout << x[i] << " " << y[i] << endl;
b[++b[]] = x[i];
b[++b[]] = y[i];
}
Hash();
SEG::build(, , b[]);
for (int i = ; i <= n; ++i)
{
in[x[i]].push_back(i);
out[y[i]].push_back(i);
SEG::update(, , b[], x[i], y[i], );
}
int res = ;
for (int i = ; i <= b[]; ++i)
ans[i] = SEG::query(, , b[], i);
for (int i = ; i <= b[]; ++i)
{
for (auto it : in[i])
SEG::update(, , b[], x[it], y[it], -);
res = max(res, ans[i] + SEG::a[].Max);
for (auto it : out[i])
SEG::update(, , b[], x[it], y[it], );
}
printf("%d\n", res);
}
return ;
}
Problem D Go Latin
Solved.
按题意模拟。
#include <bits/stdc++.h>
using namespace std; int t;
map <string, string> mp; int main()
{
mp["a"] = "as";
mp["i"] = "ios";
mp["y"] = "ios";
mp["l"] = "les";
mp["n"] = "anes";
mp["ne"] = "anes";
mp["o"] = "os";
mp["r"] = "res";
mp["t"] = "tas";
mp["u"] = "us";
mp["v"] = "ves";
mp["w"] = "was";
ios::sync_with_stdio(false);
cin.tie(); cout.tie();
cin >> t;
string s;
while (t--)
{
cin >> s;
int len = s.size();
string tmp = "";
tmp += s[len - ];
if (mp.find(tmp) != mp.end())
{
s.erase(s.begin() + len - );
s += mp[tmp];
}
else
{
tmp = "";
tmp += s[len - ];
tmp += s[len - ];
if (mp.find(tmp) != mp.end())
{
s.erase(s.begin() + len - , s.end());
s += mp[tmp];
}
else
s += "us";
}
cout << s << "\n";
}
return ;
}
ProblemE LED
Upsolved.
题意:求一个分段函数的最小最大值
思路:
注意$v = 0$的时候,其余部分二分,贪心验证
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 300010
struct node
{
ll v, l;
void scan()
{
scanf("%lld%lld", &v, &l);
l *= 10ll;
}
bool operator < (const node &other) const { return v < other.v; }
}a[N];
int n; bool check(ll x)
{
int i;
ll l1, l2;
for (i = ; i <= n; ++i)
{
if (a[i].l > x)
break;
}
if (i > n) return true;
ll Max = , Min = (ll)1e11;
for (; i <= n; ++i)
{
Max = max(Max, a[i].l);
Min = min(Min, a[i].l);
if (Max - (Max + Min) / > x)
break;
l1 = (Max + Min) / ;
}
if (i > n) return true;
Max = , Min = (ll)1e11;
for (; i <= n; ++i)
{
Max = max(Max, a[i].l);
Min = min(Min, a[i].l);
if (Max - (Max + Min) / > x)
break;
l2 = (Max + Min) / ;
}
//cout << x << " " << l1 << " " << l2 << endl;
if (i <= n) return false;
return l2 >= l1;
} int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) a[i].scan();
sort(a + , a + + n);
ll base = ;
int j = ;
for (int i = ; i <= n; ++i)
{
if (a[i].v == )
base = max(base, a[i].l);
else
a[++j] = a[i];
}
n = j;
ll l = , r = (ll)1e11, res = -;
while (r - l >= )
{
ll mid = (l + r) >> ;
if (check(mid))
{
res = mid;
r = mid - ;
}
else
l = mid + ;
}
res = max(res, base);
ll x = res % ;
res /= ;
printf("%lld.%lld\n", res, x);
}
return ;
}
ProblemF Parentheses
Upsolved.
题意:给出一个表达式,先判合法性,再判是否有括号冗余或者缺少。
思路:
直接判吧,数据里面有一个空行,不要多组读入。。。
vp的时候以为有(-b)这种东西,实际上没有。
#include <bits/stdc++.h>
using namespace std; #define N 1000100
char s[N];
int id[N], len; bool ok()
{
len = strlen(s + );
for (int i = ; i <= len; ++i)
{
if (isalpha(s[i]))
id[i] = ;
else if (s[i] == '+' ||
s[i] == '-' ||
s[i] == '*' ||
s[i] == '/' ||
s[i] == '%')
id[i] = ;
else if (s[i] == '(')
id[i] = ;
else
id[i] = ;
}
if (id[] == || id[len] == ) return false;
if (id[] == || id[len] == ) return false;
if (len == && id[] == )
return true;
for (int i = , x, y; i <= len; ++i)
{
x = id[i - ], y = id[i];
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
if (x == && y == )
return false;
}
int cnt = ;
for (int i = ; i <= len; ++i)
{
if (id[i] == )
++cnt;
else if (id[i] == )
{
if (cnt == )
return false;
--cnt;
}
}
return cnt == ;
} // 0 alpha
// 1 + - * / %
// 2 (
// 3 ) bool work()
{
if (len == ) return true;
int cnt = , sym = ;
for (int i = ; i <= len; ++i)
sym += (id[i] == );
stack <int> sta;
for (int i = ; i <= len; ++i)
{
if (id[i] == )
continue;
else if (id[i] <= )
sta.push(id[i]);
else if (id[i] == )
{
int flag = ;
while (!sta.empty())
{
int top = sta.top(); sta.pop();
if (top == )
break;
if (top == )
++flag;
}
if (flag == ) ++cnt;
else
return false;
}
}
return cnt == sym - ;
} int main()
{
gets(s + );
{
len = strlen(s + );
//if (len == 0) continue;
int now = ;
for (int i = ; i <= len; ++i)
if (s[i] != ' ')
s[++now] = s[i];
s[++now] = ;
// cout << s + 1 << endl;
if (!ok()) puts("error");
else
puts(work() ? "proper" : "improper");
}
return ;
}
ProblemK TV Show Game
Solved.
题意:$k$个灯, $n$个人, 每个人猜三个位置的灯的颜色, 要求构造出使得所有人都猜对两个或两个以上数量的灯的颜色的序列。
思路:枚举每个灯的状态, 2-SAT求解。
(2-SAT 不熟练啊 果然还是需要练一练)
#include<bits/stdc++.h> using namespace std; const int maxn = 1e4 + ; struct node{
int lamp1, lamp2, lamp3;
int color1, color2, color3;
}arr[maxn]; int k, n;
int vis[maxn << ];
vector<int>People[maxn], lamp[maxn];//R 0 B 1
int Stack[maxn], top; void Init()
{
for(int i = ; i < maxn; ++i) People[i].clear();
for(int i = ; i < maxn; ++i) lamp[i].clear();
} bool DFS(int u)
{
if(vis[u ^ ]) return false;
if(vis[u]) return true;
vis[u] = ;
Stack[top++] = u;
for(auto it : lamp[u])
{
for(auto v : People[it]) if(v != u)
{
if(!DFS(v ^ )) return false;
}
}
return true;
} bool Twosat(int n)
{
memset(vis, , sizeof vis);
for(int i = ; i <= n; i += )
{
if(vis[i] || vis[i ^ ]) continue;
top = ;
if(!DFS(i))
{
while(top) vis[Stack[--top]] = ;
if(!DFS(i ^ )) return false;
}
}
return true;
} int main()
{
while(~scanf("%d %d", &k, &n))
{
Init();
for(int i = ; i <= n; ++i)
{
char a, b, c;
scanf("%d %c %d %c %d %c", &arr[i].lamp1, &a, &arr[i].lamp2, &b, &arr[i].lamp3, &c); arr[i].color1 = (a == 'B');
arr[i].color2 = (b == 'B');
arr[i].color3 = (c == 'B'); People[i].push_back(arr[i].lamp1 * + (arr[i].color1 ^ ));
lamp[arr[i].lamp1 * + (arr[i].color1 ^ )].push_back(i); People[i].push_back(arr[i].lamp2 * + (arr[i].color2 ^ ));
lamp[arr[i].lamp2 * + (arr[i].color2 ^ )].push_back(i); People[i].push_back(arr[i].lamp3 * + (arr[i].color3 ^ ));
lamp[arr[i].lamp3 * + (arr[i].color3 ^ )].push_back(i);
}
if(Twosat( * k))
{
for(int i = ; i <= k; ++i)
{
if(vis[ * i]) putchar('R');
else putchar('B');
}
putchar('\n');
}
else puts("-1");
}
return ;
}
ProblemL Working Plan
Solved.
题意:$m$个人, $n$天, 每个人一旦开始工作需要连续工作$w$天, 工作完w天后需要休息$h$天, 每天需要$d_i$个人, 每个人要求工作$W_i$天, 求方案。
思路:贪心, 优先使得剩余工作天数多的人工作。
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e3 + ; struct node{
int id;
int st, ed;
int workday;
node(){}
node(int id, int st, int ed, int workday): id(id), st(st), ed(ed), workday(workday){}
bool operator < (const node &other) const{
if(st != other.st) return st > other.st;
else return workday < other.workday;
}
}; bool cmp(node a, node b)
{
return a.workday < b.workday;
} int n, m,w, h;
int W[maxn], d[maxn];
priority_queue<node>q;
priority_queue<int, vector<int>, greater<int> >Day;
vector<int>ans[maxn];
node Stack[maxn];
int top; void Init()
{
while(!q.empty()) q.pop();
while(!Day.empty()) Day.pop();
for(int i = ; i <= m; ++i) ans[i].clear();
} int main()
{
while(~scanf("%d %d %d %d", &m, &n, &w, &h))
{
Init();
for(int i = ; i <= m; ++i) scanf("%d", W + i);
for(int i = ; i <= n; ++i) scanf("%d", d + i);
for(int i = ; i <= m; ++i) q.push(node(i, , , W[i]));
bool flag = true;
int cnt = ;
top = ;
for(int i = ; i <= n; ++i)
{
while(!Day.empty())
{
if(Day.top() < i) Day.pop();
else break;
}
int daysize = Day.size();
if(daysize > d[i])
{
flag = false;
break;
}
if(daysize == d[i]) continue;
while(!q.empty())
{
if(q.top().st <= i)
{
Stack[++top] = q.top();
q.pop();
}
else
{
break;
}
}
sort(Stack + , Stack + + top, cmp);
while(Day.size() < d[i])
{
if(top < )
{
flag = false;
break;
}
node tmp = Stack[top--];
tmp.st = i;
ans[tmp.id].push_back(i);
tmp.st += w;
Day.push(tmp.st - );
tmp.st += h;
tmp.workday -= min(w, n - i + );
if(tmp.workday) q.push(tmp);
else cnt++;
}
if(Day.size() != d[i]) flag= false;
if(flag == false) break;
}
if(cnt != m) flag = false;
if(flag)
{
puts("");
for(int i = ; i <= m; ++i) for(int j = , len = ans[i].size(); j < len; ++j) printf("%d%c", ans[i][j], " \n"[j == len - ]);
}
else puts("-1");
}
return ;
}
2018-2019 ACM-ICPC, Asia Seoul Regional Contest的更多相关文章
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...
- 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K
传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...
- 2018 ICPC Asia Jakarta Regional Contest
题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 . : 待补 A. Edit Distance Thin ...
- Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...
- Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP
题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...
- Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律
题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...
- Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流
题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...
- Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖
题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...
- Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数
题面 题意:1e6的数组(1<a[i]<1e6), mul (l,r) =l × (l+1) ×...× r, fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...
随机推荐
- python2.0_s12_day9_协程&多线程和cpu,磁盘io之间的关系
事件驱动和异步io有什么直接关系. 当我们访问一个网页,不考虑网络问题.我们人类不觉得网页慢. 但是实际中对计算机来说还是慢.那慢在哪里.io io操作是整个网络操作中最慢的.比如你打开网页要是有2秒 ...
- json 数据分析
/* 健一健康头条 */ try { String url = "http://www.j1health.com/j1api.php/index/getJ1healthHotLists&qu ...
- Android的读写文件及权限设置
drwx read write excute openFileOutput(name,drwx); 用系统api读取文件 设置文件生成的权限: public static boolean sav ...
- win10下安装Oracle 11g 32位客户端遇到INS-13001环境不满足最低要求
在以管理员身份运行setup.exe之后,出现了:[INS-13001]环境不满足最低要求,通过网上搜索之后找到了解决途径 首先,打开你的解压后的database文件夹,找到stage,然后cvu,找 ...
- x86 体系指令
FASM 第二章 - 2.1 x86 体系指令 Author: 徐艺波 From: xuyibo.org Updated: 2008-04-17 官方论坛 本站软件反馈.软件开发交流. ...
- deferred对象(摘自别人的文章)
对jQuery中的deferred对象的整体认识: Deferred是个工厂类,返回的是内部构建的deferred对象 tuples 创建三个$.Callbacks对象,分别表示成功,失败,处理中三种 ...
- Fatal error Using $this when not in object context in
大致意思是 $this 没有上下文,原因是没有对此类进行实例化. 出现此错误的原因是:在FileCommand.php中使用 $this->方法/属性. $this 不是不可以用,而是要看情况用 ...
- python的类继承与派生
一.继承和派生简介: 其实是一个一个事物站在不同角度去看,说白了就是基于一个或几个类定义一个新的类.比如定义了动物类接着派生出了人类,你也可以说人类继承了动物类.一个意思.此外python类似于C和C ...
- 真机远程页面调试工具spy-debugger 3.x:集成weinre+AnyProxy,页面调试+抓包。调试生产HTTPS页面。
.页面调试+抓包 2.操作简单 3.支持HTTPS. 4.spy-debugger内部集成了weinre.node-mitmproxy.AnyProxy. 5.自动忽略原生App发起的https请求, ...
- Redis字符串类型的操作
set key value [ex 秒数] / [px 毫秒数] [nx] /[xx] 如: set a 1 ex 10 , 10秒有效 Set a 1 px 9000 , 9秒有效 注: 如果ex ...