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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K

    传送门:https://codeforces.com/gym/102082/attachments 题解: 代码: /** * ┏┓ ┏┓ * ┏┛┗━━━━━━━┛┗━━━┓ * ┃ ┃ * ┃ ━ ...

  4. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

  5. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  6. 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的长 ...

  7. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  8. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  9. Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖

    题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...

  10. 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 ...

随机推荐

  1. python2.0_s12_day19_前端结合后端展示客户咨询纪录

    接下来就是将后台视图与前端页面结合起来了完成后台系统了.实现前端展示用户列表1.先在base.html代码中把模版中Dashboard下面的内容清空,如下: 具体删除哪些html代码,自己找吧.2.我 ...

  2. 基于Cocos2d-x学习OpenGL ES 2.0系列——OpenGL ES渲染之LayerColor(8)

    在前面文章中讲述了Cocos2d-x引擎OpenGL渲染准备Shader方面,本文主要讲解使用LayerColor来讲述OpenGL的渲染过程. 1.LayerColor对象创建 添加LayerCol ...

  3. Core Location和MapKit的一些简单使用

      Core Location 1. 基本对象是CLLocation,有属性coordinate, altitude, horizontal/vertical Accuracy, timestamp, ...

  4. codeforce 148D. Bag of mice[概率dp]

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. navicat 激活流程

    Navicat Premium 12激活 我自己测试了一下可以激活,很好用 原作链接:https://blog.csdn.net/loveer0/article/details/82016644 Na ...

  6. 【BZOJ3677】[Apio2014]连珠线 换根DP

    [BZOJ3677][Apio2014]连珠线 Description 在列奥纳多·达·芬奇时期,有一个流行的童年游戏,叫做“连珠线”.不出所料,玩这个游戏只需要珠子和线,珠子从1到礼编号,线分为红色 ...

  7. SqlServer复杂存储过程

    SqlServer复杂存储过程 CREATE PROCEDURE FETCH_GOOUT_INFO AS BEGIN WITH l as(SELECT A.ZJHM, O.KSQR, O.JSRQ, ...

  8. onethink重新安装后,还原数据库后,登陆不了解决办法!

    在用onethink开发的时候,为了防止修改出错,我会在开发下一个功能的对上一个功能代码整体进行备份,如果出错就返回上一个版本再次修改. 但是会发现一个问题,如果如果返回到上一个版本,重新安装完成之后 ...

  9. Android 性能测试工具- GT

    GT(随 身调)是APP的随身调测平台,它是直接运行在手机上的“集成调测环境”(IDTE, Integrated Debug&Test Environment).利用GT,仅凭一部手机,无需连 ...

  10. #pragma预处理命令详解

    #pragma预处理命令 #pragma可以说是C++中最复杂的预处理指令了,下面是最常用的几个#pragma指令: #pragma comment(lib,"XXX.lib") ...