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代码速度提高,细节要考虑清楚。

官方题解

Round374


A. One-dimensional Japanese Crossword

time limit per test

1 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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).

Output

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.

input
3BBW

output
12

input
13WBBBBWWBWBBBW

output
34 1 3 

Note

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=110;
inline LL gi() {register LL w=0,q=0;register char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')q=1,ch=getchar();while(ch>='0'&&ch<='9')w=w*10+ch-'0',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=0;scanf("%s",s);for(int i=0;i<n;i++)if(s[i]=='B'){int j=i;k++;while(s[j++]=='B')a[k]++;i=j-1;}printf("%d\n",k);for(int i=1;i<=k;i++)printf("%d ",a[i]);return 0;
}

B. Passwords

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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).

Input

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.

Output

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.

input
5 2cbaabcbb1abCABCabc

output
1 15

input
4 10011221222

output
3 4

Note

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=110;
const int MAXM=100010;
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=0,q=0;register char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')q=1,ch=getchar();while(ch>='0'&&ch<='9')w=w*10+ch-'0',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=0;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=1;i<=n;i++)a[i].read();scanf("%s",c);int i,l=strlen(c),ans=0;sort(a+1,a+1+n);for(i=1;i<=n;i++){if(a[i].l>=l)break;ans++;if(i%k==0)ans+=5;}printf("%d ",ans+1);int kk=(i-1)%k;for(;i<=n;i++){if(a[i].l>l)break;if(a[i].pan()){ans++;kk++;if(kk%k==0)ans+=5;}}printf("%d",ans+1);return 0;
}

C. Journey

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

input
4 3 131 2 52 3 72 4 8

output
31 2 4

input
6 6 71 2 21 3 33 6 32 4 24 6 26 5 1

output
41 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=5010;
const int MAXM=MAXN<<1;
inline LL gi() {register LL w=0,q=0;register char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')q=1,ch=getchar();while(ch>='0'&&ch<='9')w=w*10+ch-'0',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][1]=0;return;}if(used[x])return;used[x]=true;for(int i=fr[x];i;i=ne[i]){dfs(to[i]);for(int j=1;j<=n;j++){if(f[to[i]][j-1]==be)continue;if(f[to[i]][j-1]+W[i]>T)continue;//..会爆intif(f[to[i]][j-1]+W[i]<f[x][j]){f[x][j]=f[to[i]][j-1]+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=1;i<=m;i++){int u=gi(),v=gi(),w=gi();add(u,v,w);}memset(f,123,sizeof(f));be=f[1][1];dfs(1);int i;for(i=n;i;i--)if(f[1][i]<=T)break;printf("%d\n",i);for(int o=1;i;i--){printf("%d ",o);o=d[o][i];}return 0;
}

D. Maxim and Array

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

input
5 3 15 4 3 5 2

output
5 4 3 5 -1

input
5 3 15 4 4 5 5

output
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=200010;
inline LL gi() {register LL w=0,q=0;register char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')q=1,ch=getchar();while(ch>='0'&&ch<='9')w=w*10+ch-'0',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=0;for(int i=1;i<=n;i++)a[i]=gi(),q.push((node){a[i]<0?-a[i]:a[i],i}),b+=a[i]<0;while(k--){int p=q.top().p;q.pop();b-=a[p]<0;if(b&1)a[p]+=x;else a[p]-=x;b+=a[p]<0;q.push((node){a[p]<0?-a[p]:a[p],p});}for(int i=1;i<=n;i++)printf("%lld ",a[i]);return 0;
}

转载于:https://www.cnblogs.com/YJinpeng/p/5926473.html

【Codeforces】 Round #374 (Div. 2)相关推荐

  1. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  2. 【Codeforces】Round #375 (Div. 2)

    Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...

  3. 【CodeForces】Round #436

    A FairGame //Fair Game //一道裸的模拟题而已 //二十分钟了...mdzz //虽然英文蛋疼 #include<iostream> #include<map& ...

  4. 【codeforces】Round #269 ABCD

    A:判断熊象,六个参数,有4个是腿,必须一样,另外两个如果相同是象,不同是熊,不符合要求是喵星人! B:给出几个数,将他们以不下降的方式排一下,若有三种及其以上排法,输出YES,然后任意输出三种排法( ...

  5. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新

    http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...

  6. 【Codeforces】925A Stairs and Elevators【贪心】

    [Codeforces]925A Stairs and Elevators [题目大意] 在一个n*m的矩阵里,有clcl个楼梯和cece个电梯,电梯和楼梯可以到任意一层,给出clcl个楼梯的位置和c ...

  7. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

  8. 【CodeForces】[546A]Soldier and Bananas

    直接运算 并没有什么弯 注意int就足以储存数据 不需要借钱时(n>res) 输出 0 #include<stdio.h> int main() {int k,n,w;while(s ...

  9. 【LeetCode】第374题——猜数字大小(难度:简单)

    [LeetCode]第374题--猜数字大小(难度:简单) 题目描述 解题思路 代码详解 注意点 题目描述 猜数字游戏的规则如下: 每轮游戏,我都会从 1 到 n 随机选择一个数字. 请你猜选出的是哪 ...

最新文章

  1. 5/29 c的结构体变量
  2. JavaScript 运行时错误: 无法获取未定义或 null 一种解决方案
  3. 05-VTK在图像处理中的应用(2)
  4. 危机之后迎来机遇,企业对抗疫情的11点建议
  5. pkpm板按弹性计算还是塑性_PKPM中的S\R验算显红原因分析
  6. 《软件需求十步走》阅读笔记06
  7. 前端小知识点(1):undefined和null区别
  8. 渗透测试入门16之渗透测试基本知识
  9. Mysql之索引详解
  10. Ubuntu 安装极点五笔 for ibus
  11. 走近汇编理解与内核编程
  12. 你没听过的IT技术解读,能秒懂的都是老司机...
  13. Xshell5和Xftp传输工具的安装和配置
  14. arcgis栅格数据绘制等值线_arcgis 栅格函数之等值线
  15. python转化excel数字日期为标准日期
  16. 马甲包上架经验总结(珍贵)
  17. CC00024.CloudOpenStack——|OpenStack组件.V02|——|OpenStack-Cinder块存储|配置block.V2|
  18. 关于“.”与“->”使用的区别
  19. 央企招聘:中国航空油料集团2023公开招聘
  20. Python 计时器(秒钟、秒表)

热门文章

  1. java技术入门培训_入门java怎么自学?推荐谁的课程?
  2. android屏幕适配的五种方式_讲一讲Android 9.0系统的新特性,对刘海屏设备进行适配...
  3. 中法线如何反转_凹凸贴图、法线贴图、置换贴图傻傻分不清?
  4. python 画在同一坐标轴_Python学习第95课-多个数据在同一个坐标轴画图叠加
  5. 织梦Cms怎么一直服务器维护中,织梦cms文档关键词维护中频率详解
  6. mysql 自带 数据库_mysql自带的4个数据库介绍
  7. python丢失api-ms-win-crt-process_api-ms-win-crt-process-l1-1-0.dll 丢失的处理,遇到问题和完美解决...
  8. 从零开始学习docker(十四)Docker Compose--build
  9. Vector源码分析
  10. 期权定价理论及其matlab实现过程,期权定价理论及其Matlab实现过程