ACM-ICPC 2018 徐州赛区网络预赛
A. Hard to prepare
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+;
long long bit[];
long long f[]; int main() {
int T;
int n,k;
bit[] = ;
for (int i = ; i <= ; i++) {
bit[i] = *bit[i-]%MOD;
}
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
f[] = bit[k];
long long t1 = (bit[k]-+MOD)%MOD;
long long t2 = (bit[k]-+MOD)%MOD;
f[] = f[]*t1%MOD;
for (int i = ; i <= n; i++) {
f[i] = (f[i-]*t1%MOD+(f[i-]-f[])*t2%MOD)%MOD;
f[i] = (f[i] + MOD)%MOD;
}
printf("%d\n", (int)f[n]);
}
return ;
}
B. BE, GE or NE
#include <bits/stdc++.h>
using namespace std; int n;
int dp[][];
int a[][];
const int INF = 0x3f3f3f3f; int gao(int i, int now) {
if (i >= n) return now-;
if (dp[i][now] != INF) {
return dp[i][now];
}
if (i% == ) {
int ans = -;
int tmp = now-;
if (a[i][] > ) {
int nn = min(tmp+a[i][], );
ans = max(ans, gao(i+, nn+));
}
if (a[i][] > ) {
int nn = max(tmp-a[i][], -);
ans = max(ans, gao(i+, nn+));
}
if (a[i][] > ) {
ans = max(ans, gao(i+, -tmp+));
}
dp[i][now] = ans;
return ans;
} else {
int ans = ;
int tmp = now-;
if (a[i][] > ) {
int nn = min(tmp+a[i][], );
ans = min(ans, gao(i+, nn+));
}
if (a[i][] > ) {
int nn = max(tmp-a[i][], -);
ans = min(ans, gao(i+, nn+));
}
if (a[i][] > ) {
ans = min(ans, gao(i+, -tmp+));
}
dp[i][now] = ans;
return ans;
}
} int main() {
int m,k,l;
while(scanf("%d%d%d%d", &n, &m, &k, &l) == ) {
for (int i = ; i < n; i++) {
scanf("%d%d%d", &a[i][], &a[i][], &a[i][]);
}
for (int i = ; i <= n; i++)
for (int j = ; j <= ; j++)
dp[i][j] = INF;
int ans = gao(, m+);
if (ans >= k)puts("Good Ending");
else if(ans <= l) puts("Bad Ending");
else puts("Normal Ending");
}
return ;
}
C. Cacti Lottery
#include <bits/stdc++.h>
using namespace std; int getScore(int s) {
switch(s) {
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
case : return ;
}
} char mp[][]; int a[][]; double sum;
double num; long long cnt = ;
double r[];
double c[];
double dd[]; void gao(bool used[], int x, int y) {
/*
if (x >= 3) {
printf("*** x %d y %d\n",x, y);
for (int i = 1; i <= 9; i++)
printf("%d ", used[i]);
printf("\n");
for(int i = 0; i < 3; i++) {
for(int j = 0;j < 3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
}
*/ if (x >= ) {
for (int i = ; i < ; i++) {
int tmp = ;
for (int j = ; j < ; j++)
tmp += a[i][j];
r[i] += getScore(tmp);
}
for (int j = ; j < ; j++) {
int tmp = ;
for (int i = ; i < ; i++) {
tmp += a[i][j];
}
c[j] += getScore(tmp);
}
dd[] += getScore(a[][] + a[][] + a[][]);
dd[] += getScore(a[][] + a[][] + a[][]);
cnt++;
return;
}
int nx = x;
int ny = y+;
if (ny >= ) {
ny = ;
nx++;
}
if (mp[x][y] != '#') {
gao(used, nx, ny);
} else {
for (int i = ; i <= ; i++) {
if (!used[i]) {
used[i] = true;
a[x][y] = i;
gao(used, nx, ny);
a[x][y] = ;
used[i] = false;
}
}
}
} void dfs(bool used[], int x, int y) {
/*
if (x >= 3) {
printf("x %d y %d\n",x, y);
for (int i = 1; i <= 9; i++)
printf("%d ", used[i]);
printf("\n");
for(int i = 0; i < 3; i++) {
for(int j = 0;j < 3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
}
*/
if (x >= ) {
cnt = ;
for (int i = ; i < ; i++) {
r[i] = ;
c[i] = ;
}
dd[] = ;
dd[] = ;
gao(used, , );
double tmp = ;
for (int i = ; i < ; i++) {
tmp = max(tmp, r[i]);
tmp = max(tmp, c[i]);
}
tmp = max(tmp, dd[]);
tmp = max(tmp, dd[]);
sum += tmp/cnt;
num += ;
return;
}
int nx = x;
int ny = y+;
if (ny >= ) {
nx++;
ny = ;
}
if (mp[x][y] != '*') {
dfs(used, nx, ny);
} else {
for (int i = ; i <= ; i++) {
if (!used[i]) {
used[i] = true;
a[x][y] = i;
dfs(used, nx, ny);
a[x][y] = ;
used[i] = false;
}
}
}
} int main() {
int T;
scanf("%d", &T);
while (T--) {
for (int i = ; i < ; i++)
scanf("%s", mp[i]);
sum = ;
num = ;
bool used[];
memset(used, false, sizeof(used));
memset(a, , sizeof(a));
for(int i = ; i < ; i++)
for (int j = ; j < ; j++) {
if (mp[i][j] >= '' && mp[i][j] <= '') {
used[mp[i][j] -''] = true;
a[i][j] = mp[i][j]-'';
}
}
dfs(used, , );
printf("%.10f\n", sum/num);
}
return ;
}
D. Easy Math
E. End Fantasy VIX
F. Features Track
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>;
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + ; int t;
int n, m;
pair<int,int>s;
map<pair<int, int>, int>sum;
map<pair<int, int>, int>flag;
set<pair<int,int> >v; int main()
{
scanf("%d", &t);
while(t--)
{
int ans = ;
v.clear();
sum.clear();
scanf("%d", &n);
while(n--)
{
flag.clear();
scanf("%d", &m);
if(m == )
{
v.clear();
sum.clear();
}
for(int i = ; i < m; i++)
{
int a, b;
scanf("%d %d", &a, &b);
s.first = a;
s.second = b;
if(!flag[s])
sum[s]++;
flag[s] = ;
v.insert(s);
ans = max(ans, sum[s]);
}
pair<int, int> cnt[];
int d = ;
for(set<pair<int,int> >::iterator it = v.begin();it != v.end();it++)
{
if(flag[*it] == )
cnt[d++] = *it;
}
for(int i = ; i < d; i++)
{
v.erase(cnt[i]);
sum[cnt[i]] = ;
}
}
printf("%d\n",ans);
}
return ;
}
G. Trace
#include <bits/stdc++.h>
using namespace std; long long gao(vector<int> vec) {
int sz = vec.size();
set<int>st;
long long ans = ;
for (int i = sz-; i >= ; i--) {
set<int>::iterator it = st.lower_bound(vec[i]);
if (it == st.begin()) {
ans += vec[i];
} else {
it--;
ans += vec[i] - *it;
}
st.insert(vec[i]);
}
return ans;
}
int main() {
int n;
while(scanf("%d", &n) == ) {
vector<int>vec1, vec2;
int x,y;
while(n--) {
scanf("%d%d", &x, &y);
vec1.push_back(x);
vec2.push_back(y);
}
cout<<gao(vec1) + gao(vec2)<<endl;
}
}
H. Ryuji doesn't want to study
#include <iostream>
#include <stdio.h>
#define ll long long
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std;
int n;
const int MAXN = 1e5 + ;
ll sum[MAXN << ];
ll add[MAXN << ]; void push_up(int rt){//向上更新
sum[rt] = sum[rt << ] + sum[rt << | ];
} void push_down(int rt, int m){
if(add[rt]){//若有标记,则将标记向下移动一层
add[rt << ] += add[rt];
add[rt << | ] += add[rt];
sum[rt << ] += (m - (m >> )) * add[rt];
sum[rt << | ] += (m >> ) * add[rt];
add[rt] = ;//取消本层标记
}
} void build(int l, int r, int rt){//建树
add[rt] = ;
if(l == r){
scanf("%lld", &sum[rt]);
return;
}
int mid = (l + r) >> ;
build(lson);
build(rson);
push_up(rt);//向上更新
} void update(int L, int R, ll key, int l, int r, int rt){//区间更新
if(L <= l && R >= r){
sum[rt] = (r - l + ) * key;
add[rt] = key;
return;
}
push_down(rt, r - l + );//向下更新
int mid = (l + r) >> ;
if(L <= mid) update(L, R, key, lson);
if(R > mid) update(L, R, key, rson);
push_up(rt);//向上更新
} ll query(int L, int R, int l, int r, int rt){//区间求和
if(L <= l && R >= r) return sum[rt];
push_down(rt, r - l + );//向下更新
int mid = (l + r) >> ;
ll ans = ;
if(L <= mid) ans += query(L, R, lson);
if(R > mid) ans += query(L, R, rson);
return ans;
}
//-----------------------------------
ll sum2[MAXN << ];
ll add2[MAXN << ]; void push_up2(int rt){//向上更新
sum2[rt] = sum2[rt << ] + sum2[rt << | ];
} void push_down2(int rt, int m){
if(add2[rt]){//若有标记,则将标记向下移动一层
add2[rt << ] += add2[rt];
add2[rt << | ] += add2[rt];
sum2[rt << ] += (m - (m >> )) * add2[rt];
sum2[rt << | ] += (m >> ) * add2[rt];
add2[rt] = ;//取消本层标记
}
} void build2(int l, int r, int rt){//建树
add2[rt] = ;
if(l == r){
sum2[rt]=sum[rt]*(n-l+);
return;
}
int mid = (l + r) >> ;
build2(lson);
build2(rson);
push_up2(rt);//向上更新
} void update2(int L, int R, ll key, int l, int r, int rt){//区间更新
if(L <= l && R >= r){
sum2[rt] = (r - l + ) * key;
add2[rt] = key;
return;
}
push_down2(rt, r - l + );//向下更新
int mid = (l + r) >> ;
if(L <= mid) update2(L, R, key, lson);
if(R > mid) update2(L, R, key, rson);
push_up2(rt);//向上更新
} ll query2(int L, int R, int l, int r, int rt){//区间求和
if(L <= l && R >= r) return sum2[rt];
push_down2(rt, r - l + );//向下更新
int mid = (l + r) >> ;
ll ans = ;
if(L <= mid) ans += query2(L, R, lson);
if(R > mid) ans += query2(L, R, rson);
return ans;
} int main(void){
int m;
scanf("%d%d", &n, &m);
build(, n, );
build2(, n, );
while(m--){
ll x, y;
ll z;
scanf("%lld%lld%lld",&x,&y,&z);
if(x==){
ll ans=query(y,z,,n,);
ll ans2=query2(y,z,,n,);
printf("%lld\n",ans2-ans*(n-z));
}else{
update(y,y,z,,n,);
update2(y,y,z*(n-y+),,n,);
}
}
}
I. Characters with Hash
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + ; int t;
int n;
char ch[];
string str; int main()
{
scanf("%d", &t);
while(t--)
{
int num;
ll ans = ;
int cnt = ;
scanf("%d %s", &n, ch);
cin>>str;
int len = str.size();
int flag=;
for(int i = ;i < len; i++)
{
num = abs(str[i]- ch[]);
if(flag==) {
if (num != ) {
if (num / == ) {
ans += ;
} else if (num / == ) {
ans += ;
}
flag = ;
}
}else{
ans+=;
}
}
if(ans == )
ans++;
printf("%lld\n",ans);
}
return ;
}
J. Maze Designer
#include <bits/stdc++.h>
using namespace std; const int MAXN = ;
const int DEG = ; struct Edge{
int to,next;
int w;
}edge[MAXN*];
int head[MAXN],tot;
void addedge(int u,int v, int w){
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].w = w;
head[u] = tot++;
}
void init(){
tot = ;
memset(head,-,sizeof(head));
}
int fa[MAXN][DEG];//`fa[i][j]琛ㄧず缁撶偣i鐨勭`2^j`涓鍏坄
int deg[MAXN];//`娣卞害鏁扮粍` void BFS(int root){
queue<int>que;
deg[root] = ;
fa[root][] = root;
que.push(root);
while(!que.empty()){
int tmp = que.front();
que.pop();
for(int i = ;i < DEG;i++)
fa[tmp][i] = fa[fa[tmp][i-]][i-];
for(int i = head[tmp]; i != -;i = edge[i].next){
int v = edge[i].to;
if(v == fa[tmp][])continue;
deg[v] = deg[tmp] + ;
fa[v][] = tmp;
que.push(v);
} }
}
int LCA(int u,int v){
if(deg[u] > deg[v])swap(u,v);
int hu = deg[u], hv = deg[v];
int tu = u, tv = v;
for(int det = hv-hu, i = ; det ;det>>=, i++)
if(det&)
tv = fa[tv][i];
if(tu == tv)return tu;
for(int i = DEG-; i >= ; i--){
if(fa[tu][i] == fa[tv][i])
continue;
tu = fa[tu][i];
tv = fa[tv][i];
}
return fa[tu][];
} struct Node {
int u,v,w;
}node[];
bool cmp(Node a, Node b) {
return a.w > b.w;
} int F[];
int find(int x) {
if(F[x] == -)return x;
else return F[x] = find(F[x]);
}
void bing(int x, int y) {
int t1 = find(x);
int t2 = find(y);
if (t1 != t2)F[t1] = t2;
} int main() {
int n,m;
while(scanf("%d%d", &n, &m) == ) {
int cnt = ;
for (int i = ; i < n; i++)
for (int j = ; j < m; j++) {
int u = i*m + j;
char op[];
int w;
for(int t = ; t<; t++) {
scanf("%s%d", op, &w);
if (op[] == 'X')continue;
int v;
if (op[] == 'D' && i < n-) {
v = (i+)*m + j;
} else if (op[] == 'R' && j < m-) {
v = i*m+j+;
} else {
continue;
}
node[cnt].u = u;
node[cnt].v = v;
node[cnt++].w = w;
}
}
sort(node, node+cnt, cmp); init();
memset(F, -, sizeof(F));
for (int i = ; i < cnt; i++) {
int u = node[i].u;
int v = node[i].v;
if (find(u) != find(v)) {
bing(u, v);
addedge(u,v,node[i].w);
addedge(v,u,node[i].w);
}
}
BFS(); int Q;
scanf("%d", &Q);
int x1,y1,x2,y2;
while(Q--) {
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int u = (x1-)*m+y1-;
int v = (x2-)*m + y2-;
int lca = LCA(u,v);
printf("%d\n", deg[u]+deg[v] - *deg[lca]);
} return ; }
return ;
}
K. Morgana Net
ACM-ICPC 2018 徐州赛区网络预赛的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
- ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash
Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...
- ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和
链接 https://nanti.jisuanke.com/t/31456 参考题解 https://blog.csdn.net/ftx456789/article/details/82590044 ...
- ACM-ICPC 2018 徐州赛区网络预赛(8/11)
ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...
随机推荐
- 提高PHP编程效率的20个要点
用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中 ...
- collectd 与 logstash配置
节点 node1: 配置logstash node2: 配置collectd, collectd收集本地的信息, 通过配置将信息发送到node1节点 node1安装配置logstash rpm -iv ...
- Freetype 安装时提示 make: Nothing to be done for `unix'
[Software-Freetype] Freetype 安装时提示 make: Nothing to be done for `unix' 官网下载的第三方软件包,编译安装会报以下错误,解决办法如下 ...
- 学习笔记:MDN的服务器端网站编程
互联网是如何工作的 互联网(Internet)和网络(web) 互联网是基础设施,网络是建立在这种基础设施之上的服务. 网页,网站,网络服务器和搜索引擎的区别是什么? 网页(webpage) 一份能够 ...
- C++ 关于运算符重载
转载来源:http://c.biancheng.net/cpp/biancheng/view/216.html 重载运算符的函数一般格式如下: 函数类型 operator 运算符名称 (形参表列 ...
- linux 命令——3 pwd (转)
Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...
- ABAP Netweaver和Cloud Foundry上的环境变量Environment Variable
Netweaver 更准确的说应该是系统变量:结构体sy 设一个断点,调试器里看这些字段的值就能知道每个字段是用来做什么的. sy-dbsys sy-sysid sy-opsys sy-saprl s ...
- JavaScript模块化开发的那些事
模块化开发在编程开发中是一个非常重要的概念,一个优秀的模块化项目的后期维护成本可以大大降低.本文主要介绍了JavaScript模块化开发的那些事,文中通过一个小故事比较直观地阐述了模块化开发的过程. ...
- CDQ分治入门
前言 \(CDQ\)分治是一个神奇的算法. 它有着广泛的用途,甚至在某些题目中还能取代\(KD-Tree\).树套树等恶心的数据结构成为正解,而且常数还小得多. 不过它也有一定的缺点,如必须离线操作, ...
- 索引属性 name指定
创建索引时的格式: db.collection.ensureIndex({param},{param}) 其中,第一个是索引的值,之前一直只用到了第一个,第二个参数便是索引的属性 比较重要的属性有: ...