2018 ACM 网络选拔赛 南京赛区
A. An Olympian Math Problem
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=1e5+; int main()
{
int t;
ll n;
scanf("%d",&t);
while (t--)
{
scanf("%lld",&n);
printf("%lld\n",n-);
}
return ;
}
B. The writing on the wall
与 https://leetcode.com/problems/maximal-rectangle/description/ 这道题很像
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+;
const int maxn=1e5+;
const int maxm=1e2+; int a[maxn][maxm],c[maxn][maxm];
int qx[maxm],qy[maxm]; int main()
{
ll sum=;
int t,T,n,m,g,x,y,i,j,k;
bool vis;
scanf("%d",&t);
for (T=;T<=t;T++)
{
memset(a,,sizeof(a));
scanf("%d%d%d",&n,&m,&g);
while (g--)
{
scanf("%d%d",&x,&y);
a[x][y]=;
}
for (j=;j<=m;j++)
for (i=;i<=n;i++)
c[i][j]=(a[i][j]==)?:c[i-][j]+;
sum=;
for (i=;i<=n;i++)
{
///以a[i][j]作为右下方
g=;
for (j=;j<=m;j++)
{
if (g== || c[i][j]>qx[g])
vis=;
else
vis=;
sum+=c[i][j];
qy[g+]=j; while (qx[g]>c[i][j])
sum+=1ll*(qy[g+]-qy[g])*c[i][j],g--;
k=g;
while (k)
sum+=1ll*(qy[k+]-qy[k])*qx[k],k--;
if (g== || qx[g]!=c[i][j])
g++;
if (vis)
qy[g]=j;
qx[g]=c[i][j];
}
}
printf("Case #%d: %lld\n",T,sum);
}
return ;
}
/*
100
3 3 3
1 1
1 2
2 1 3 3 4
1 1
1 2
2 1
2 2 2 3 0 100000 100 0
*/
C. GDY
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=2e2+;
const int maxm=2e4; int s[maxm],a[maxn][maxm],g[maxn];
int value[]={,,,,,,,,,,,,,}; int cmp(int x,int y)
{
return value[x]>value[y];
} int main()
{
int t,T,n,m,num,i,j,sum;
int x,y,z;
scanf("%d",&t);
for (T=;T<=t;T++)
{
memset(g,,sizeof(g)); scanf("%d%d",&n,&m);
for (i=;i<m;i++)
scanf("%d",&s[i]);
num=;
for (i=;i<n;i++)
{
for (j=;j<;j++)
{
if (num==m)
break;
a[i][j]=s[num++];
}
sort(a[i],a[i]+j,cmp);
g[i]=j;
} z=a[][g[]-];//previous number
g[]--;
y=;//has y persons
x=;//pos
while ()
{
for (i=g[x]-;i>=;i--)
if (value[z]+==value[a[x][i]] || (a[x][i]== && z!=))
break; if (i!=-)
{
z=a[x][i];
a[x][i]=;
sort(a[x],a[x]+g[x],cmp);
g[x]--;
if (g[x]==)
break;
y=;
}
else if (y!=n-)
y++;
else
{
x=(x+)%n;
for (i=x;;i=(i+)%n)
{
if (num==m)
break;
else
{
a[i][g[i]++]=s[num++];
sort(a[i],a[i]+g[i],cmp);
}
if (i==(x-+n)%n)
break;
} z=a[x][g[x]-];
g[x]--;
if (g[x]==)
break;
y=;
} x=(x+)%n;
}
printf("Case #%d:\n",T);
for (i=;i<n;i++)
if (i==x)
printf("Winner\n");
else
{
sum=;
for (j=;j<g[i];j++)
sum+=a[i][j];
printf("%d\n",sum);
}
}
return ;
}
/*
10
2 6
3 5 7 9 11 4 3 20
2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 3 19
2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 3 20
3 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 10
3 4 5 6 7 2 3 4 5 6 3 15
3 4 5 6 7 12 12 12 12 12 13 13 13 13 13 3 11
1 2 3 4 5 6 7 8 9 10 11 3 13
1 2 3 4 5 6 7 8 9 10 11 12 13 1
3 17
1 2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 */
E. AC Challenge
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf -1e18
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=1e5+; ll f[<<]; struct node
{
ll value;
int pos,t;
}; struct cmp1
{
bool operator() (node a,node b)
{
return a.value>b.value;
}
}; //priority_queue<node>st;
priority_queue<node,vector<node>,cmp1>st;
int er[],a[],b[],v[]; int main()
{
int n,m,s,i,j,value,pos,t;
ll r=,rr;
for (i=;i<;i++)
er[i]=(<<i); scanf("%d",&n);
for (i=;i<(<<n);i++)
f[i]=inf; for (i=;i<n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&m);
v[i]=;
while (m--)
{
scanf("%d",&s);
v[i]+=(er[s-]);
}
if (v[i]==)
{
f[er[i]]=a[i]+b[i];
st.push({a[i]+b[i],er[i],});
r=max(r,(ll)a[i]+b[i]);
}
} while (!st.empty())
{
value=st.top().value;
pos=st.top().pos;
t=st.top().t;
st.pop();
for (i=;i<n;i++)
if ((pos & er[i])== && (pos & v[i])==v[i] && value+1ll*t*a[i]+b[i]>f[pos|er[i]])
{
rr=value+1ll*t*a[i]+b[i];
f[pos|er[i]]=rr;
r=max(r,rr);
st.push({rr,pos|er[i],t+});
}
}
printf("%lld",r);
return ;
}
/*
3
1 2 0
1 5 0
8 1 0
*/
G. Lpl and Energy-saving Lamps
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e18
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=1e5+; struct node
{
int x,y;
}f[maxn],r[maxn]; int tag[maxn<<],a[maxn],x,y; int cmp(node a,node b)
{
return a.x<b.x;
} void build(int index,int l,int r)
{
if (l==r)
scanf("%d",&tag[index]);
else
{
int m=(l+r)>>;
build(index<<,l,m);
build(index<<|,m+,r);
tag[index]=min(tag[index<<],tag[index<<|]);
}
} int query(int index,int l,int r,int v)
{
if (l==r)
{
if (tag[index]>v)
return ; x++;
y-=tag[index];
tag[index]=inf;
return l;
}
else
{
int m=(l+r)>>,z;
if (tag[index<<]<=v)
z=query(index<<,l,m,v); else
z=query(index<<|,m+,r,v);
tag[index]=min(tag[index<<],tag[index<<|]);
return z;
}
} int main()
{
int n,m,q,Q,d,index,i,j;
scanf("%d%d",&n,&m);
build(,,n); scanf("%d",&q);
for (Q=;Q<=q;Q++)
{
scanf("%d",&d);
f[Q].x=d;
f[Q].y=Q;
}
sort(f+,f+q+,cmp); index=;
x=;
y=;
for (i=;i<=f[q].x;i++)
{
y+=m;
j=;
while (j)
j=query(,,n,y); while (f[index].x==i)
{
r[f[index].y]={x,y};
index++;
}
} for (i=;i<=q;i++)
printf("%d %d\n",r[i].x,r[i].y);
return ;
}
J. Sum
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e9
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=2e7+; int zhi[maxn],f[maxn];
bool vis[maxn],v[maxn]; int main()
{
int t,i,j,k,x=,y=,value=2e7;
ll n,sum;
memset(vis,,sizeof(vis));
memset(v,,sizeof(v));
for (i=;i<=value;i++)
{
if (!vis[i])
{
x++;
zhi[x]=i;
}
for (j=;j<=x;j++)
{
k=i*zhi[j];
if (k>value)
break;
vis[k]=;
v[k]=v[i];
if (i%zhi[j]==)
{
v[k]=;
break;
}
}
}
for (i=;i<=value;i++)
if (!v[i])
{
y++;
f[y]=i;
} // for (i=1;i<=100;i++)
// printf("%d ",f[i]); scanf("%d",&t);
f[]=;
while (t--)
{
scanf("%lld",&n);
sum=;
j=y;
for (i=;i<=y;i++)
{
while (1ll*f[i]*f[j]>n)
j--;
sum+=j;
}
printf("%lld\n",sum);
}
return ;
}
L. Magical Girl Haze
/*
图问题:
spfa容易被卡时间复杂度 而dijkstra是贪心,不会被卡
*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <time.h>
#include <string>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <ext/rope>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long
#define minv 1e-6
#define inf 1e18
#define pi 3.1415926536
#define nl 2.7182818284
const ll mod=1e9+;//
const int maxn=1e5+; struct rec
{
int d,len;
rec *to;
}*e[maxn]; struct node
{
ll dist;
int k,d;
}; struct cmp1
{
bool operator() (node a,node b)
{
if (a.dist==b.dist)
return a.k>b.k;
else
return a.dist>b.dist;
}
}; priority_queue<node,vector<node>,cmp1>st; ll f[maxn][]; int main()
{
rec *p;
int t,n,m,k,i,j,d,kk,dd,x,y,z;
ll dist,r;
scanf("%d",&t);
while (t--)
{
scanf("%d%d%d",&n,&m,&k);
for (i=;i<=n;i++)
e[i]=NULL;
while (m--)
{
scanf("%d%d%d",&x,&y,&z);
p=(rec*) malloc (sizeof(rec));
p->d=y;
p->len=z;
p->to=e[x];
e[x]=p;
}
for (i=;i<=n;i++)
for (j=;j<=k;j++)
f[i][j]=inf;
for (j=;j<=k;j++)
{
f[][j]=;
st.push({,j,});
}
//f[i][j]作为一个状态,100000*10
while (!st.empty())
{
dist=st.top().dist;
d=st.top().d;
kk=st.top().k;
st.pop();
p=e[d];
while (p)
{
dd=p->d;
if (f[dd][kk]>dist+p->len)
{
f[dd][kk]=dist+p->len;
st.push({f[dd][kk],kk,dd});
}
if (kk!=k && f[dd][kk+]>dist)
{
f[dd][kk+]=dist;
st.push({f[dd][kk+],kk+,dd});
}
p=p->to;
}
}
r=inf;
for (j=;j<=k;j++)
r=min(r,f[n][j]);
printf("%lld\n",r);
}
return ;
}
2018 ACM 网络选拔赛 南京赛区的更多相关文章
- 2018 ACM 网络选拔赛 青岛赛区
一些题目的代码被网站吞了…… Problem B. Red Black Tree http://acm.zju.edu.cn/onlinejudge/searchProblem.do?contestI ...
- 2018 ACM 网络选拔赛 北京赛区
A Saving Tang Monk II #include <bits/stdc++.h> using namespace std; ; struct node { int x,y,z, ...
- 2018 ACM 网络选拔赛 徐州赛区
A. Hard to prepare #include <cstdio> #include <cstdlib> #include <cmath> #include ...
- 2018 ACM 网络选拔赛 焦作赛区
A. Magic Mirror #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- 2018 ACM 网络选拔赛 沈阳赛区
B. Call of Accepted #include <cstdio> #include <cstdlib> #include <cmath> #include ...
- ACM-ICPC 2018 南京赛区网络预赛 J.sum
A square-free integer is an integer which is indivisible by any square number except 11. For example ...
- ACM-ICPC 2018 南京赛区网络预赛 E题
ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest wi ...
- ACM-ICPC 2018 南京赛区网络预赛B
题目链接:https://nanti.jisuanke.com/t/30991 Feeling hungry, a cute hamster decides to order some take-aw ...
- 计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)
J. Sum 26.87% 1000ms 512000K A square-free integer is an integer which is indivisible by any squar ...
随机推荐
- Apache之Rewrite和RewriteRule规则梳理以及http强转https的配置总结
一. 简单实例介绍一般来说,apache配置好http和https后,如果想要做http强转到https,需要设置url重定向规则,大致需要下面几个步骤即可完成配置: 1)在httpd.conf文件里 ...
- Haproxy+Keepalived高可用环境部署梳理(主主和主从模式)
Nginx.LVS.HAProxy 是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,通常会结合Keepalive做健康检查,实现故障转移的高可用功能. 1)在四层(tcp)实现负载均衡的 ...
- Ubuntu14.04安装PyMuPDF
最近写的一个东西需要将pdf转成图片然后放在网页上展示,找到了个非常好用的轮子叫做PyMuPDF,在windows上测试的时候跑的666,在ubuntu上安装依赖的时候,简直万脸懵逼.github上给 ...
- github个人作业
信息学院本科生课程设计 题目 文件加密和解密 课程名称 面向对象程序设计课程设计 课程编号 X031749 所在专业 计算机科学与技术 所在班级 计科高职13-3 ...
- 接口(interface)与多态
1. 接口(interface)是抽象方法与常量值的集合: 2. 从本质上来讲,接口是一种特殊的抽象类,这种抽象类中只包含常量与方法的定义,而没有变量和方法的实现: 3. 接口中声明的属性默认为:pu ...
- Quartz中时间表达式的设置-----corn表达式 (转)(http://www.cnblogs.com/GarfieldTom/p/3746290.html)
Quartz中时间表达式的设置-----corn表达式 (注:这是让我看比较明白的一个博文,但是抱歉,没有找到原作者,如有侵犯,请告知) 时间格式: <!-- s m h d m w(?) y( ...
- Linux列举所有隐藏文件
ll 命令是 ls -l的缩写 ls -a是列举所有(all)文件,包含隐藏文件,以.开头的文件. ls -l是以列表(list)方式列举文件. http://bbs.chinaunix.net/th ...
- delphi DBGRID 刷新定位问题 [问题点数:0分]
我程序是 adoquery+datasource+dbgrid 做的我有一个窗体:有四个按钮.分别是新建,修改,删除,刷新. 新建第一条记录,dbgrid显示一条记录,新建第二条记录.DBGRID总共 ...
- Lucene 分析的意思是按照某种规则进行内容拆分 支持模糊搜索
Lucene 分析的意思是按照某种规则进行内容拆分 里面的域的值是拆分后的内容
- Luogu3835 【模板】可持久化平衡树(fhq-treap)
fhq-treap,也即非旋treap,可以在不进行旋转操作的前提下维护treap.由于不需要旋转,可以对其可持久化. fhq-treap的基本操作是merge和split,并且通过这两个操作实现对t ...