这套题不难,但是场上数据水,导致有很多叉点

A.

因为是让求删掉一个后字典序最小,那么当a[i]>a[i+1]的时候,删掉a[i]一定最优!这个题有个叉点,当扫完一遍如果没有满足条件的,就删去最后一个字符。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <stack> using namespace std;
const double eps = 1e-;
const int MOD=1e9+;
typedef long long LL;
typedef unsigned long long ull;
const int INF=;
const LL inf = 1e18;
LL gcd(LL a,LL b){
if(!b)return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
const int maxn=2e5+;
char s[maxn];
int n;
int main(){
scanf("%d",&n);
scanf("%s",s);
int pos=-;
for(int i=;i<n-;i++){
if(s[i+]<s[i]){
pos=i;
break;
}
}
if(pos==-)
pos=n-;
for(int i=;i<n;i++)
if(i!=pos)
printf("%c",s[i]);
return ;
}

B.

当n是偶数的时候一定是每次都减2,也就是n/2.当n奇数的时候,就暴力减质数一直减到是偶数或者为0.注意要特判当前n是不是质数。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <stack> using namespace std;
const double eps = 1e-;
const int MOD=1e9+;
typedef long long LL;
typedef unsigned long long ull;
const int INF=;
const LL inf = 1e18;
LL gcd(LL a,LL b){
if(!b)return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
const int maxn=2e5+; int prime[maxn];
int vis[maxn];
int num;
int init(int n){
int m = (int)sqrt(n);
vis[]=; for(int i = ;i<=m;i++){
for(int j =i*i; j<=n;j+=i){
vis[j]=;
}
}
for(int i=;i<=n;i++){
if(!vis[i]){
num++;
prime[num] = i;
}
}
return num;
}
bool judge(LL x){
int m =(int)sqrt(x);
for(int i=;i<=m+;i++){
if(x%i==)
return false;
}
return true;
}
LL n;
int
main(){
cin>>n;
LL ans=;
init(2e5);
if(n%==){
cout<<n/<<endl;
return ;
}
bool ok=;
while(n%){
if(judge(n)){
ans+=;
ok=;
break;
} int flag=;
for(int i=;i<=num&&prime[i]<=n;i++){
if(n%prime[i]==){
// printf("!!%d\n",prime[i]);
flag=prime[i];
break;
}
}
//printf("%d\n",flag);
if(!flag)flag=n;
n-=flag;
ans++;
}
if(ok)
ans+=n/;
cout<<ans<<endl;
return ;
}

C.

这个题就是解一个一元二次方程,应该也可以三分来做。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <stack> using namespace std;
const double eps = 1e-;
const int MOD=1e9+;
typedef long long LL;
typedef unsigned long long ull;
const int INF=;
const LL inf = 1e18;
LL gcd(LL a,LL b){
if(!b)return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
int main(){
int T;
scanf("%d",&T); int d;
for(int kas=;kas<=T;kas++){
scanf("%d",&d);
double del = d*d - *d;
if(del<){
printf("N\n");
}else if(del == ){
double ans=(double)d/; printf("Y %.9f %.9f\n",ans,(double)(d-ans));
}else{
double ans1 = (double)(d+sqrt(del))/;
if(ans1<=d){
printf("Y %.9f %.9f\n",ans1,(double)(d-ans1));
}else{
double ans1 = (double)(d-sqrt(del))/;
if(ans1<){
printf("N\n");
}else
printf("Y %.9f %.9f\n",ans1,(double)(d-ans1));
}
}
}
return ;
}

D.

最短路+贪心;我们先跑出最短路树来,如果k大于等于最短路树的边数,则树上的边全留下。否则的话就要删树上的边,删哪些呢?从最远(d[u]最大)的边开始删一定是最优的。

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <stack> using namespace std;
const double eps = 1e-;
const int MOD=1e9+;
typedef long long LL;
typedef unsigned long long ull;
const int INF=;
const LL inf = 1e18;
LL gcd(LL a,LL b){
if(!b)return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
const int maxn=3e5+;
int head[maxn],to[*maxn],Next[*maxn],w[*maxn],id[*maxn];
struct Edge{
int from,to,w,id;
};
vector<Edge>edges;
int sz,n,m,k;
void init(){
sz=;
memset(head,-,sizeof(head));
}
void add_edge(int a,int b,int c,int d){
++sz;
to[sz]=b;
w[sz]=c;
id[sz]=d;
Next[sz]=head[a];
head[a]=sz;
}
struct HeapNode{
int u;
LL d;
int from;
bool operator <(const HeapNode& rhs)const{
return d>rhs.d;
}
};
int done[maxn],p[maxn];
LL d[maxn]; Edge edge[maxn]; priority_queue<HeapNode>q;
void dij(){
q.push((HeapNode){,,-});
for(int i=;i<=n;i++)
d[i]=inf;
while(!q.empty()){
HeapNode x= q.top();q.pop();
if(done[x.u])
continue;
done[x.u]=;
d[x.u] = x.d;
p[x.u] = x.from;
//printf("%d\n",x.from);
for(int i=head[x.u];i!=-;i=Next[i]){
int v = to[i];
if(d[v]>d[x.u]+w[i]){
q.push((HeapNode){v,d[x.u]+w[i],id[i]});
}
}
}
} struct Node{
int u;
LL d;
int from;
bool operator <(const Node &rhs)const{
return d<rhs.d;
}
};
int vis[maxn]; priority_queue<Node>Q; int main(){
scanf("%d%d%d",&n,&m,&k); init();
for(int i=;i<=m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add_edge(a,b,c,i);
add_edge(b,a,c,i);
edge[i]=(Edge){a,b,c,i};
}
dij();
for(int i=;i<=n;i++){
//printf("@%d\n",p[i]);
if(p[i]!=-&& !vis[p[i]]){
edges.push_back(edge[p[i]]);
vis[p[i]]=;
Q.push((Node){i,d[i],p[i]});
// printf("!!!%d %d %d %d\n",edge[p[i]].from,edge[p[i]].to,edge[p[i]].w,p[i]);
}
}
if(edges.size()<=k){
printf("%d\n",edges.size());
for(int i=;i<edges.size();i++){
printf("%d ",edges[i].id);
}
}else{
int num = edges.size();
while(num>k&&!Q.empty()){
Q.pop();
num--;
}
printf("%d\n",k);
while(!Q.empty()){
printf("%d ",Q.top().from);
Q.pop();
}
}
return ;
}

E.

树状数组或者线段树维护一下。因为每个点的值只可能是来自于它的祖先结点,所以跑dfs的时候,进入这个点的时候更新树状数组,退栈的时候还原树状数组

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector> using namespace std;
const int maxn=3e5+;
typedef long long LL;
int head[maxn],to[*maxn],Next[*maxn];
int n,sz,m;
void add_edge(int a,int b){
sz++;
to[sz]=b;Next[sz]=head[a];head[a]=sz;
}
int lowbit(int x){
return x&(-x);
}
LL sumv[maxn];
void update(int x,int v){
while(x<=n){
sumv[x]+=v;
x+=lowbit(x);
}
}
LL query(int x){
LL res=;
while(x){
res+=sumv[x];
x-=lowbit(x);
}
return res;
}
struct Node{
int d,x;
};
vector<Node>V[maxn];
int fa[maxn],dep[maxn];
LL ans[maxn]; void dfs(int u,int Fa,int depth){
fa[u]=Fa;
dep[u]=depth;
for(int i=;i<V[u].size();i++){
Node N = V[u][i];
update(min(N.d+depth,n),N.x);
}
ans[u] = query(n)-query(depth-);
for(int i=head[u];i!=-;i=Next[i]){
int v=to[i];
if(v==Fa)continue;
dfs(v,u,depth+);
}
for(int i=;i<V[u].size();i++){
Node N = V[u][i];
update(min(N.d+depth,n),-N.x);
}
} int main(){
scanf("%d",&n);
memset(head,-,sizeof(head));
for(int i=;i<n;i++){
int a,b;
scanf("%d%d",&a,&b);
add_edge(a,b);
add_edge(b,a);
}
scanf("%d",&m);
for(int i=;i<=m;i++){
int v,d,x;
scanf("%d%d%d",&v,&d,&x);
V[v].push_back((Node){d,x});
}
dfs(,-,);
for(int i=;i<=n;i++){
printf("%I64d ",ans[i]);
}
return ;
}

F.

贪心+分类讨论。

每一页多的为Max,少的为Min。那么一定是用少的将多的分隔开。所以如果大小关系不同则不会产生影响。否则的话,这一页我们要它最左边多出来的那块尽量长。lef=k-lastR;那么Max=Max-lef,Min=Min-1;然后我们分类讨论:

1.ceil(Max/k)-1>Min 则return false;

2.ceil(Max/k)<=Min

则说明右边不会剩下。则lastR=0。

3.ceil(Max/k)==Min-1的话,恰好被分割开,右边会有剩余,但是剩余的长度<=k,属于合法。
lastR= Max%k ==0?k:Max%k

这个也有叉点,要主要Min==Max的情况

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib> using namespace std;
const int maxn = 3e5 + ;
int n, k;
int x[maxn][];//0 x,1 y
int state,laststate,lastR;
int main(){
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++){
scanf("%d", &x[i][]);
}
for(int i = ; i <= n; i++){
scanf("%d", &x[i][]);
}
bool flag = ;
for(int i = ; i <= n; i++){ //x >= y state = 1;else state = 0;
int Min = min(x[i][], x[i][]);
int Max = max(x[i][], x[i][]);
// printf("%d %d\n",Min,Max);
if(x[i][] > x[i][])
state = ;
else if(x[i][] < x[i][])
state = ;
else state = -;
if(state == laststate||laststate == -||state == -){
int lef = k - lastR;
Max = Max - lef;
Min = Min - ;
}
//printf("%d %d\n",(int)ceil((double)Max/k),Min); if((int)ceil((double)Max/k)- > Min){
flag = ;
break;
}else if((int)ceil((double)Max/k) <= Min){
lastR = ;
}else{
lastR = Max%k == ?k:Max%k;
}
laststate = state;
}
if(!flag){
printf("NO\n");
}else{
printf("YES\n");
}
return ;
}

G.

好像是打反转标记的线段树,留坑

Educational Codeforces Round 54的更多相关文章

  1. Educational Codeforces Round 54 (Rated for Div. 2) D:Edge Deletion

    题目链接:http://codeforces.com/contest/1076/problem/D 题意:给一个n个点,m条边的无向图.要求保留最多k条边,使得其他点到1点的最短路剩余最多. 思路:当 ...

  2. Educational Codeforces Round 54 ---1076ABCDE

    1076A---Minimizing the String[字符串] http://codeforces.com/contest/1076/problem/A 题意: 删掉字符串中的一个字符使得得到的 ...

  3. Educational Codeforces Round 54 E. Vasya and a Tree(树上差分数组)

    https://codeforces.com/contest/1076/problem/E 题意 给一棵树(n<=3e5),m(3e5)次查询,每次查询u,d,x,表示在u的子树中,给距离u&l ...

  4. Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)

    第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...

  5. Educational Codeforces Round 54 (Rated for Div. 2) Solution

    A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...

  6. Educational Codeforces Round 54 (Rated for Div. 2) DE

    D 给出一个无向图,需要删去一些边,想知道最后能有多少个点到1的距离还是过去那么短 如果求一个最短路,然后从删边的角度看,看起来很难做,但是如果从零开始加边就会有做法,如同prim那样,先加入和1直接 ...

  7. Educational Codeforces Round 54 (Rated for Div. 2) ABCD

    A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...

  8. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  9. Educational Codeforces Round 54 (Rated for Div. 2) D Edge Deletion (SPFA + bfs)

    题目大意:给定你一个包含n个点m条边的无向图,现在最多在图中保留k条边,问怎么删除多的边,使得图中良好的节点数最多,求出保留在图中的边的数量和编号. 良好的节点定义为:删除某条边后该点到点1的最短距离 ...

随机推荐

  1. Cobbler自动化安装部署系统

    自动化安装部署 https://www.cnblogs.com/nulige/p/6796593.html PXE+Kickstart工作原理 pxe+kickstart工作流程 网卡上的pxe芯片有 ...

  2. I.MX6 Manufacturing Tool V2 (MFGTool2) Update Command List (UCL) User Guide translate

    Manufacturing Tool V2 (MFGTool2) Update Command List (UCL) User Guide Contents(目录) Contents(目录)     ...

  3. kudu yum 安装

    yum 源 http://archive.cloudera.com/kudu/redhat/7/x86_64/kudu/cloudera-kudu.repo [cloudera-kudu] # Pac ...

  4. Windows 2008 关闭远程桌面的单用户多会话模式

    Windows 2008 关闭远程桌面的单用户多会话模式 在腾讯云上购买了一台云服务器. 因为设置了自动登录,在远程桌面连接后会启动一个新的会话,然后软件被运行了两次,端口被占用,无法起动. 还有可能 ...

  5. Hive之 数据类型

    hive 目前支持的数据类型如下: -- 数值类型 Numeric TypesTINYINT (1-byte signed integer, from -128 to 127)SMALLINT (2- ...

  6. 移植wpa_supplicant2.5及界面配置wifi(原创)

    JP5G开发机上需要图形界面配置 wifi网络,为此移植了wpa_supplicant2.5. 1.参考wpa_supplicant-2.5移植与使用l http://blog.csdn.net/hk ...

  7. (判断)window.open()窗口被关闭后执行事件

    $(function() { // start ready var $article_share=$('#body .article').find('li.share'); // $article_s ...

  8. MoveWindow() SetWindowPos()的区别于联系

    敲代码时,突然发现有一个背景图片无法显示,百思不得其解,最终发现是MoveWindow() SetWindowPos()这两个函数的使用不当造成的. 这里把这两个函数的前世今生给分析一下. 先看Mov ...

  9. Tomcat 容器的设计和实现

    Tomcat 容器是对 Servlet 规范的实现,也称为 Servlet 引擎.在分析 Tomcat 容器的设计和实现之前,首先简单了解一下 Servlet 规范,弄清楚 Tomcat 究竟要实现什 ...

  10. Centos6.5安装phpldapadmin

    phpLDAPadmin是一个基于Web的LDAP管理工具用于管理LDAP服务器的各个方面.你可以利用它浏览LDAP Tree,创建/删除/修改和复制节点(entry) ,执行搜索,导入/导出LDIF ...