【Codeforces】 Round #374 (Div. 2)
Position:http://codeforces.com/contest/721
我的情况
开始还是rank1,秒出C。(11:00机房都走光了,我ma到11:05才走,只打了一个小时)
结果。。。
FST!!尤其是第一题还WA了一发。gi烂。B题还ma得慢。
最后滚到青名。。。。。
反思
首先每次都WA了A题,很不应该,虽然快,样例都没测就交,结果丢了50分。
B题ma得慢。
C题未考虑到LL情况,虽然有上界T,但我没用啊,直接记录到这个点的用了几个点的最短距离,dfs时没有判断与T的关系。统计答案才判,结果FST,WA烂,掉raiting。
D不能怪没时间。很水但没做?问题,人家一个小时也可以AK。我觉得还是分析问题能力要提升,ma代码速度提高,细节要考虑清楚。
官方题解
A. One-dimensional Japanese Crossword
1 seconds
256 megabytes
standard input
standard output
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.
The example of encrypting of a single row of japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
3
BBW
1
2
13
WBBBBWWBWBBBW
3
4 1 3
The last sample case correspond to the picture in the statement.
Understanding
求一个字符串中连续一段B出现的个数,并输出每段的数目
Solution
模拟?枚举→CF官方implementation(翻译:贯彻实施扫一遍→运用吧)。O(n)将字符串扫一遍,如果发现一个'B',往后找'B',记录个数即可
Introspection
A题wa了一发,50分啊,raiting啊。
以后一定要测样例,并且考虑到各种特殊的情况,n=1,极限数据爆LL
下次拿小号开黑。。。只要不skip就行。
Code
// <A.cpp> - Fri Sep 30 22:03:52 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN=;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
char s[MAXN];int a[MAXN];
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
int n=gi(),k=;
scanf("%s",s);
for(int i=;i<n;i++)
if(s[i]=='B'){
int j=i;k++;
while(s[j++]=='B')a[k]++;
i=j-;
}
printf("%d\n",k);
for(int i=;i<=k;i++)printf("%d ",a[i]);
return ;
}
B. Passwords
2 seconds
256 megabytes
standard input
standard output
Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.
Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.
Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.
The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.
Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.
5 2
cba
abc
bb1
abC
ABC
abc
1 15
4 100
11
22
1
2
22
3 4
Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.
Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.
Understanding
给你很多个输入的密码,并且给你正确的密码(保证输入的中有正确的密码)。求输入顺序使得最少与最多的此时可以得到密码,要求按字符串长度顺序输出。
Solution
贪心。记每个字符串的长度,sort。最小:把长度小的输完,然后再输出+1就行。最大:长度小的输完+长度相等并且不等于密码串的个数+1。
Code
// <B.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=;
const int MAXM=;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
char c[MAXN];
struct node{
char s[MAXN];int l;
bool operator<(node b)const{return l<b.l;}
void read(){scanf("%s",s);l=strlen(s);}
bool pan(){
for(int i=;i<l;i++)
if(s[i]!=c[i])return true;
return false;
}
}a[MAXN];
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
int n=gi(),k=gi();
for(int i=;i<=n;i++)a[i].read();
scanf("%s",c);int i,l=strlen(c),ans=;
sort(a+,a++n);
for(i=;i<=n;i++){
if(a[i].l>=l)break;
ans++;
if(i%k==)ans+=;
}
printf("%d ",ans+);int kk=(i-)%k;
for(;i<=n;i++){
if(a[i].l>l)break;
if(a[i].pan()){
ans++;kk++;if(kk%k==)ans+=;
}
}
printf("%d",ans+);
return ;
}
C. Journey
3 seconds
256 megabytes
standard input
standard output
Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.
Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.
Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.
The first line of the input contains three integers n, m and T (2 ≤ n ≤ 5000, 1 ≤ m ≤ 5000, 1 ≤ T ≤ 109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.
The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ ti ≤ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.
It is guaranteed, that there is at most one road between each pair of showplaces.
Print the single integer k (2 ≤ k ≤ n) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.
Print k distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.
If there are multiple answers, print any of them.
4 3 13
1 2 5
2 3 7
2 4 8
3
1 2 4
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
4
1 2 4 6
Understanding
给你一个DAG(有向无环图),求1~n路径中,走过点数最多,且边权和<=T的方案。
Solution
记忆化搜索,f[i][j]记录,第i个点走到n号点经过j的最小边权和。转移:f[i][j]=min{f[son][j-1]+w[edge]}
每次转移用d[i][j]记录它转到的儿子。
Code
// <C.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
const int MAXN=;
const int MAXM=MAXN<<;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
int n,tot,be,T;
int to[MAXM],ne[MAXM],fr[MAXN],W[MAXM];
int f[MAXN][MAXN],d[MAXN][MAXN];bool used[MAXN];
void add(int u,int v,int w){
to[++tot]=v;ne[tot]=fr[u];fr[u]=tot;W[tot]=w;
}
void dfs(int x){
if(x==n){f[x][]=;return;}
if(used[x])return;used[x]=true;
for(int i=fr[x];i;i=ne[i]){
dfs(to[i]);
for(int j=;j<=n;j++){
if(f[to[i]][j-]==be)continue;
if(f[to[i]][j-]+W[i]>T)continue;//..会爆int
if(f[to[i]][j-]+W[i]<f[x][j]){
f[x][j]=f[to[i]][j-]+W[i];
d[x][j]=to[i];
}
}
}
}
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
n=gi();int m=gi();T=gi();
for(int i=;i<=m;i++){
int u=gi(),v=gi(),w=gi();
add(u,v,w);
}
memset(f,,sizeof(f));be=f[][];
dfs();int i;
for(i=n;i;i--)
if(f[][i]<=T)break;
printf("%d\n",i);
for(int o=;i;i--){
printf("%d ",o);
o=d[o][i];
}
return ;
}
D. Maxim and Array
2 seconds
256 megabytes
standard input
standard output
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer i (1 ≤ i ≤ n) and replaces the i-th element of array ai either with ai + x or with ai - x. Please note that the operation may be applied more than once to the same position.
Maxim is a curious minimalis, thus he wants to know what is the minimum value that the product of all array elements (i.e. ) can reach, if Maxim would apply no more than k operations to it. Please help him in that.
The first line of the input contains three integers n, k and x (1 ≤ n, k ≤ 200 000, 1 ≤ x ≤ 109) — the number of elements in the array, the maximum number of operations and the number invented by Maxim, respectively.
The second line contains n integers a1, a2, ..., an () — the elements of the array found by Maxim.
Print n integers b1, b2, ..., bn in the only line — the array elements after applying no more than k operations to the array. In particular, should stay true for every 1 ≤ i ≤ n, but the product of all array elements should be minimum possible.
If there are multiple answers, print any of them.
5 3 1
5 4 3 5 2
5 4 3 5 -1
5 3 1
5 4 4 5 5
5 1 4 5 5
Understanding
给你一列数和k个操作,每次操作要将一个数(+|-)x,舍得最后乘积最小。
Solution
贪心。%遥犇。首先可以想到,使结果为负会很好,如果为正,也要使其尽量小。那么记录为负的个数,开小根堆记录绝对值的最小值,每次修改最小值会是答案更小。
设a×b,a<b,(a+x)×b<a×(b+x),即证。如果剩下负数为奇数个,+x else -x。
Code
// <D.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
const int MAXN=;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
LL a[MAXN];
struct node{LL s;int p;};
priority_queue<node>q;
IN bool operator<(RG node a,RG node b){return a.s>b.s;}
int main()
{
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
int n=gi(),k=gi(),x=gi(),b=;
for(int i=;i<=n;i++)
a[i]=gi(),q.push((node){a[i]<?-a[i]:a[i],i}),b+=a[i]<;
while(k--){
int p=q.top().p;q.pop();b-=a[p]<;
if(b&)a[p]+=x;else a[p]-=x;
b+=a[p]<;q.push((node){a[p]<?-a[p]:a[p],p});
}
for(int i=;i<=n;i++)printf("%lld ",a[i]);
return ;
}
【Codeforces】 Round #374 (Div. 2)的更多相关文章
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- 【Codeforces】Round #376 (Div. 2)
http://codeforces.com/contest/731 不发题面了,自己点链接 总结一下 考场上 原以为这次要加很多raiting... 但FST狗记邓,只加了58rating 总结一下 ...
- 【Codeforces】Round #375 (Div. 2)
Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...
- 【Codeforces】Round #460 E - Congruence Equation 中国剩余定理+数论
题意 求满足$na^n\equiv b \pmod p$的$n$的个数 因为$n \mod p $循环节为$p$,$a^n\mod p$循环节为$p-1$,所以$na^n \mod p$循环 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- 【CF981F】Round Marriage(二分答案,二分图匹配,Hall定理)
[CF981F]Round Marriage(二分答案,二分图匹配,Hall定理) 题面 CF 洛谷 题解 很明显需要二分. 二分之后考虑如果判定是否存在完备匹配,考虑\(Hall\)定理. 那么如果 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- Vue课程思维导图
- The following packages have unmet dependencies:
root@ubuntu:~# apt-get install open-iscsiReading package lists... DoneBuilding dependency treeReadin ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
- 【Redis】三、Redis安装及简单示例
(四)Redis安装及使用 Redis的安装比较简单,仍然和大多数的Apache开源软件一样,只需要下载,解压,配置环境变量即可.具体安装过程参考:菜鸟教程Redis安装. 安装完成后,通过r ...
- Duboo学习-SPI
待补充 现将Dubbo-SPI相关源码流程图更新
- 在PL/SQL DEV里面有把锁一样的按钮,点击它会跳出“these query result are not updateable,include the ROWID to get updateab
在PL/SQL DEV里面有把锁一样的按钮,点击它会跳出“these query result are not updateable,include the ROWID to get updateab ...
- Luogu P2822 组合数问题
思路 组合数的话,首先肯定是想到杨辉三角啊.不傻的都知道要预处理一张组合数表,但是你以为这样就可以了吗???显然,不可能的.那询问的时候复杂度就成了$\large{O(t*n)}$,凉凉.那咋办,用二 ...
- average column data from multiple files
example in file a, data is [1 , 2, 3; 4,5,6] file b, data is [4,5, 6; 7,8,9] average=0.5 (a+b) matl ...
- BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏
直接模拟2333 #include<cstdio> #include<algorithm> using namespace std; int n,ans; void read( ...
- 51NOD 1154 回文串的划分(DP)
思路:参考了网上,思路很清奇,借助vis[i][j]来表示从i到j是否为回文串,回文串这边是用的双重循环来写的:dp[i]用来表示以i结尾的字符串最少的回文串有多长. #include<cstr ...