Educational Codeforces Round 54 (Rated for Div. 2) ABCD
1 second
256 megabytes
Description:
You are given a string ss consisting of nn lowercase Latin letters.
You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.
String s=s1s2…sns=s1s2…sn is lexicographically smaller than string t=t1t2…tmt=t1t2…tm if n<mn<m and s1=t1,s2=t2,…,sn=tns1=t1,s2=t2,…,sn=tn or there exists a number pp such that p≤min(n,m)p≤min(n,m) and s1=t1,s2=t2,…,sp−1=tp−1s1=t1,s2=t2,…,sp−1=tp−1 and sp<tpsp<tp .
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".
The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105 ) — the length of ss .
The second line of the input contains exactly nn lowercase Latin letters — the string ss .
Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string ss .
In the first example you can remove any character of ss to obtain the string "aa".
In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".
题意:
在序列中至多删去一个数,使得操作后得序列最小(与执行相同操作的其它序列相比)
题解:
通过模拟一下这个过程可以发现我们要找 i 这个位置,满足si>si+1&&i<n 或者直接i=n。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std; const int N = 2e5+;
char s[N];
int n; int main(){
scanf("%d",&n);getchar();
for(int i=;i<=n;i++) scanf("%c",&s[i]);
int i,pos=n;
for(i=;i<n;i++){
int j=i+;
if(s[j]<s[i]){
pos=i;
break ;
}
}
for(int i=;i<=n;i++){
if(i==pos) continue ;
printf("%c",s[i]);
}
return ;
}
2 seconds
256 megabytes
Description:
You are given an integer number nn. The following algorithm is applied to it:
- if n=0, then end algorithm;
- find the smallest prime divisor d of n;
- subtract d from n and go to step 1.
Determine the number of subtrations the algorithm will make.
The only line contains a single integer nn (2≤n≤10102≤n≤1010).
Print a single integer — the number of subtractions the algorithm will make.
In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.
In the second example 2 is the smallest prime divisor at both steps.
题意:
找n最小的质因子d,然后减去d,不断 重复这一过程直到n=0。
题解:
n为偶数很容易。当n为奇数时,质因子必为奇数,减去后也为偶数。所以问题的关键就是当n为奇数的情况。
最后发现只要找到一个最小的d,使得n%d==0就可以了,不管d是否为质数。
我当时没考虑到这一点,所以代码有点丑陋。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; long long n; inline int prim(int x){
int flag = ;
for(int i=;i<=sqrt(x+0.5)+;i++){
if(x%i==){
flag=;break ;
}
}
return flag;
} int main(){
scanf("%lld",&n);
if(n%==){
printf("%lld",n/);return ;
}
if(prim(n)){
printf("");return ;
}
for(int i=;i<=sqrt(n+0.5)+;i++){
if(n%i== && prim(i)){
printf("%lld",+(n-i)/);
return ;
}
}
return ;
}
1 second
256 megabytes
Try guessing the statement from this picture:
You are given a non-negative integer dd . You have to find two non-negative real numbers aa and bb such that a+b=d and a⋅b=d .
The first line contains tt (1≤t≤1031≤t≤103 ) — the number of test cases.
Each test case contains one integer d (0≤d≤103) .
For each test print one line.
If there is an answer for the i -th test, print "Y", and then the numbers a and b .
If there is no answer for the i -th test, print "N".
Your answer will be considered correct if |(a+b)−a⋅b|≤10−6|(a+b)−a⋅b|≤10−6 and |(a+b)−d|≤10−6|(a+b)−d|≤10−6 .
7
69
0
1
4
5
999
1000
Y 67.985071301 1.014928699
Y 0.000000000 0.000000000
N
Y 2.000000000 2.000000000
Y 3.618033989 1.381966011
Y 997.998996990 1.001003010
Y 998.998997995 1.00100200
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std; int t,n;
double eps = 1e-; int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
if(n==){
printf("Y 0.000000000 0.000000000\n");
continue ;
}else if(n== || n== ||n==){
printf("N\n");continue;
}else if(n==){
printf("Y 2.000000000 2.000000000\n");
continue ;
}else{
double l = ,r=,mid,Ans,tmp;
while(l<=r){
mid=(l+r)/;
tmp = n-mid;
if(abs(tmp*mid-tmp-mid)<eps || abs(tmp*mid-n)<eps){
Ans=mid;break;
}
if(tmp*mid-tmp-mid<) l=mid+0.0000000001;
else r=mid-0.0000000001;
}
printf("Y %.9lf %.9lf\n",n-Ans,Ans);
}
} return ;
}
2.5 seconds
256 megabytes
Description:
You are given an undirected connected weighted graph consisting of nn vertices and mm edges. Let's denote the length of the shortest path from vertex 11 to vertex ii as didi .
You have to erase some edges of the graph so that at most kk edges remain. Let's call a vertex ii good if there still exists a path from 11 to ii with length didi after erasing the edges.
Your goal is to erase the edges in such a way that the number of good vertices is maximized.
The first line contains three integers nn , mm and kk (2≤n≤3⋅1052≤n≤3⋅105 , 1≤m≤3⋅1051≤m≤3⋅105 , n−1≤mn−1≤m , 0≤k≤m0≤k≤m ) — the number of vertices and edges in the graph, and the maximum number of edges that can be retained in the graph, respectively.
Then mm lines follow, each containing three integers xx , yy , ww (1≤x,y≤n1≤x,y≤n , x≠yx≠y , 1≤w≤1091≤w≤109 ), denoting an edge connecting vertices xx and yy and having weight ww .
The given graph is connected (any vertex can be reached from any other vertex) and simple (there are no self-loops, and for each unordered pair of vertices there exists at most one edge connecting these vertices).
In the first line print ee — the number of edges that should remain in the graph (0≤e≤k0≤e≤k ).
In the second line print ee distinct integers from 11 to mm — the indices of edges that should remain in the graph. Edges are numbered in the same order they are given in the input. The number of good vertices should be as large as possible.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e18
using namespace std; typedef long long LL;
typedef pair<LL,int> pli;
typedef pair<int,int> pii; const int N = 3e5+;
int n,m,k;
int vis[N]={};
LL d[N];
pli pre[N];
vector<pair<int,pii> > vec[N];
vector<int> ans ;
void Dij(int x){
fill(d,d+n+,INF);d[x]=0ll;
priority_queue<pli,vector<pli>,greater<pli> > q;
q.push(make_pair(d[x],x));
while(!q.empty()){
pli now = q.top();q.pop();
int u = now.second;
if(vis[u]) continue ;
vis[u]=;
for(int i=;i<vec[u].size();i++){
int v = vec[u][i].second.first;
if(d[v]>d[u]+vec[u][i].second.second &&!vis[v]){
d[v]=d[u]+vec[u][i].second.second;
pre[v]=make_pair(u,vec[u][i].first);
q.push(make_pair(d[v],v));
}
}
}
}
queue <int> que ;
void bfs(int x,int K){
que.push(x);
while(!que.empty() && K){
int u = que.front();que.pop();
for(int i=;i<vec[u].size();i++){
int v = vec[u][i].second.first ;
if(d[v]==d[u]+vec[u][i].second.second){
que.push(v);
ans.push_back(vec[u][i].first);
K--;
}
if(!K) break ;
}
}
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=,u,v,c;i<=m;i++){
scanf("%d%d%d",&u,&v,&c);
vec[u].push_back(make_pair(i,make_pair(v,c)));
vec[v].push_back(make_pair(i,make_pair(u,c)));
}
Dij();
bfs(,k);
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++) printf("%d ",ans[i]);
return ;
}
Educational Codeforces Round 54 (Rated for Div. 2) ABCD的更多相关文章
- Educational Codeforces Round 54 (Rated for Div. 2) D:Edge Deletion
题目链接:http://codeforces.com/contest/1076/problem/D 题意:给一个n个点,m条边的无向图.要求保留最多k条边,使得其他点到1点的最短路剩余最多. 思路:当 ...
- Educational Codeforces Round 54 [Rated for Div. 2] (CF1076)
第一次在宿舍打CF 把同宿舍的妹子吵得不行... 特此抱歉QAQ A 题意:给定一个字符串, 最多删掉一个字符,使得剩余字符串字典序最小 n<=2e5 当然"最多"是假的 删 ...
- Educational Codeforces Round 54 (Rated for Div. 2) Solution
A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...
- Educational Codeforces Round 54 (Rated for Div. 2) DE
D 给出一个无向图,需要删去一些边,想知道最后能有多少个点到1的距离还是过去那么短 如果求一个最短路,然后从删边的角度看,看起来很难做,但是如果从零开始加边就会有做法,如同prim那样,先加入和1直接 ...
- Educational Codeforces Round 54 (Rated for Div. 2) D Edge Deletion (SPFA + bfs)
题目大意:给定你一个包含n个点m条边的无向图,现在最多在图中保留k条边,问怎么删除多的边,使得图中良好的节点数最多,求出保留在图中的边的数量和编号. 良好的节点定义为:删除某条边后该点到点1的最短距离 ...
- Educational Codeforces Round 56 (Rated for Div. 2) ABCD
题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- vue---day04
1. Node.js 1.1 介绍: - Node.js 是一个JavaScript运行环境,实质上是对Chrome V8引擎的封装. - Node.js 不是一个 JavaScript 框架,不同于 ...
- python操作nosql数据库之memcache
一.memcache的安装 1.memcache简介 Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象减少读取数据库的次数,从而 ...
- java字符流实现文件间的内容复制
package com.io.demo1; import java.io.FileReader; import java.io.FileWriter; public class TestFileSTr ...
- Mysql数据库的压力
rationalError: (2006, 'MySQL server has gone away') 2017年10月10日 20:04:43 阅读数:377 问题描述 使用django+celer ...
- L008之前课程实战模拟。
L008之前课程实战模拟. . 安装CentOS 6.5 X86_64 . 配置网络 . 用CRT连接服务器 . 更换源http://mirrors.163.com/.help/CentOS6-Bas ...
- thrift服务端到客户端开发简单示例
(1)首先我们在服务器端写个helloworld.thrift文件,如下所示: service HelloWorld{ string ping(1: string name), string getp ...
- Mootools 学习随笔
简单的介绍下Mootools: MooTools是一个简洁,模块化,面向对象的开源JavaScript web应用框架.在处理js.css.html时候,为web开发者提供了一个跨浏览器的js解决方案 ...
- 【个人训练】(ZOJ3983)Crusaders Quest
题意分析 和祖玛类似的那种玩法.不过是限定了九个字符,问最好情况下有几次三连碰. 暴力穷举即可.具体的做法是,先把所有"成块"的字符记录下来,然后一个一个删,再继续这样子递归做下去 ...
- NOI中“大整数加法”问题不能AC的解决建议
一.检查输入000和00相加是否出结果. 二.数组不要开小了,亲测256的数组不够.推荐1024. 附录AC程序: 如果不能AC请将256改为1024,255改为1023. #include &l ...
- GraphSAGE 代码解析(一) - unsupervised_train.py
原创文章-转载请注明出处哦.其他部分内容参见以下链接- GraphSAGE 代码解析(二) - layers.py GraphSAGE 代码解析(三) - aggregators.py GraphSA ...