第一次参加CF的比赛,MSK19.30,四个小时的时差真心累,第一次CODE到这么夜……

一开始做了A,C两题,后来做B题的时候我体力和精神集中度就很低了,导致一直WA在4……

今天起床后再刷B,终于过了……坑爹。

来看题目:

A. Mashmokh and Lights
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mashmokh works in a factory. At the end of each day he must turn off all of the lights.

The lights on the factory are indexed from 1 to
n. There are n buttons in Mashmokh's room indexed from
1 to n as well. If Mashmokh pushes button with index
i, then each light with index not less than
i that is still turned on turns off.

Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed
m distinct buttons
b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light
the index of the button that turned this light off. Please note that the index of button
bi is actually
bi, not
i.

Please, help Mashmokh, print these indices.

Input

The first line of the input contains two space-separated integers
n and m
(1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains
m distinct space-separated integers
b1, b2, ..., bm (1 ≤ bi ≤ n).

It is guaranteed that all lights will be turned off after pushing all buttons.

Output

Output n space-separated integers where the
i-th number is index of the button that turns the
i-th light off.

Sample test(s)
Input
5 4
4 3 1 2
Output
1 1 3 4 4
Input
5 5
5 4 3 2 1
Output
1 2 3 4 5
Note

In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as
well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.

英文不好的我也看懂题目了……其实意思很简单,就是关灯,关编号i的灯大于等于i的灯就会灭掉,之后给出n,k,n为灯树木,k为操作次数,接下来k个是关的灯。

贪心轻松搞掂。memset(v,0,sizeof(v)),之后关i时候就将未标记的(v[m]==0)标记为v[m]=i(m>=i),水到不行。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int v[103];
int main(){
int n;
int m,i,j,tmp;
while(cin>>n>>m){
memset(v,0,sizeof(v));
for(i=0;i<m;i++){
cin>>tmp;
for(j=tmp;j<=n;j++){
if(v[j]==0) v[j]=tmp;
} }
cout<<v[1];
for(i=2;i<=n;i++)
cout<<" "<<v[i];
cout<<endl;
} return 0; }

B题

B. Mashmokh and Tokens
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker
can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back
w tokens then he'll get dollars.

Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has
n numbers x1, x2, ..., xn. Number
xi is the number of tokens given to each worker on the
i-th day. Help him calculate for each of
n days the number of tokens he can save.

Input

The first line of input contains three space-separated integers
n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains
n space-separated integers
x1, x2, ..., xn (1 ≤ xi ≤ 109).

Output

Output n space-separated integers. The
i-th of them is the number of tokens Mashmokh can save on the
i-th day.

Sample test(s)
Input
5 1 4
12 6 11 9 1
Output
0 2 3 1 1 
Input
3 1 2
1 2 3
Output
1 0 1 
Input
1 1 1
1
Output
0 

这题目真的真的很简单,但是就因为简单,导致很多时候我们想得更简单了。。。

我一开始以为简单地取余数(弱爆了),之后我写了几组数据

1 100 99

98

1 98 99

100

1 11 4

2

1 11 4

3

发现全错掉了…

其实题目意思就是求

求最小的w满足floor(a*w/b)为最大,题中的表述就是爱代币,更爱金钱。

我的思路就是:

如果a比b大,那么直接全部换掉,输出0。

否则先计算a*w/b的向下取整m,再计算m*b/a的向上取整p,输出w-p(为什么?不明白的朋友可以用上面的数据手写一下)

…………轻松ac,为什么当时我就意识迷糊到这种题目都过不去,懊恼。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
int main(){
long long n,a,b;
long long i,j;
long m; while(cin>>n>>a>>b){ for(i=0;i<n;i++){
cin>>j;
if(a>=b){ cout<<0<<" ";
}else{
m=(a*j)/b;
m=ceil( 1.0*(m*b)/a );
cout<<j-m<<" ";
} }
cout<<endl;
}
return 0;
}

C. Mashmokh and Numbers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.

In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second
move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers
x and y from the board, he gets
gcd(x, y) points. At the beginning of the game Bimokh has zero points.

Mashmokh wants to win in the game. For this reason he wants his boss to get exactly
k points in total. But the guy doesn't know how choose the initial sequence in the right way.

Please, help him. Find n distinct integers
a1, a2, ..., an such that his boss will score exactly
k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most
109.

Input

The first line of input contains two space-separated integers
n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).

Output

If such sequence doesn't exist output -1 otherwise output
n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Sample test(s)
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note

gcd(x, y) is greatest common divisor of
x and y.

老实说,我觉得C题是一题有意思的水题,并没有上面两题那么水,主要是你的思考方式。

题目是的意思就是 要你构造n长的互异序列 {Ai}.

使得序列 中,sum[ gcd(Ai,A(i+1) ) ] =k,i=1~ n-(n%1) 且i%1==1

就是前面开始每两个的gcd加起来为k(直到没有办法组成两个,即奇数时候剩下An时候)。

如果不可能的话输出-1。

首先来分析下,什么叫做不可能

很简单,因为gcd(a,b)最小也为1,当Pair数目p= (n-(n%1))/2大于k时候,那么肯定是-1.

这是下界不满足。

上界不满足,最大的gcd(a,b)会不会比k小呢?仔细看范围,只有当n=1时候,k>0才有可能,因为Ai可以达到10^9次方,而k最多也就10^8,n最都也就是10^5。

但是n=1,k=0是输出1(或者其他,随便……)n=1,k>0,输出-1。

-1的情况考虑完后,怎么构造这个序列呢?其实很简单,真的很简单。

我们Pair的数目p,p-1对互素,使得tmp=p-1,剩下用一对来构造A1,A2,gcd(A1,A2)=k-tmp即可。

我的构造方法是: A1=k-tmp,A2=2*A1,Ai=Ai-1+1.

因为 P 与  P+1总是互素(P>1,而A1,A2的构造刚好排除了P=1情况),轻松AC。

PS:不能忘记剪枝N=1,的情况,不然会WA 4

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; int main(){
int n,k; cin>>n>>k;
int pair=n/2 ;
if(pair>k ){
cout<<-1<<endl; //下界
}else if(n==1){
if(k==0) {
cout<<1<<endl;
}else cout<<-1<<endl; }else{ if(pair==k){ for(int i=1;i<=n;i++)
cout<<i<<" "; cout<<endl; }else{
pair--; //用一对来构造
int tmp=k-pair;
cout<<tmp<<" "<<2*tmp;
tmp=2*(k-pair);
for(int i=1;i<=n-2;i++){
cout<<" "<<tmp+i; }
cout<<endl;
} } return 0;
}

待续。

CF Round#240题解的更多相关文章

  1. CF Round #808 题解 (Div. 2 ABCD)

    后面题太难搞不动 . ABCD 的题解写的好水啊,感觉在写闲话,,, A 若 \(\forall i, a_1\mid a_i\),则可以 . 注意判 \(0\) 的情况 . 提交记录 . B 显而易 ...

  2. CF Round #829 题解 (Div. 2)

    F 没看所以摆了 . 看拜月教教主 LHQ 在群里代打恰钱 /bx 目录 A. Technical Support (*800) B. Kevin and Permutation (*800) C. ...

  3. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  4. CF Round #580(div2)题解报告

    CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...

  5. CFEducational Codeforces Round 66题解报告

    CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...

  6. CF Round #551 (Div. 2) D

    CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...

  7. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

  8. UOJ #30. [CF Round #278] Tourists

    UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...

  9. Codeforces Round #556 题解

    Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...

随机推荐

  1. 10个强大的Apache开源模块

    1.单点登录模块 LemonLDAP LemonLdap可以很棒地实现Apache的SSO功能,并且可以处理超过 20 万的用户请求.LemonLdap支持Java, PHP, .Net, Perl, ...

  2. ASP.Net IE10 _doPostBack 未定义错误【转】

    --昨天发现IE10下面ReportViewer执行报表会报错,发现为Js报_doPostBack 未定义错误,查找相关资料发现问题为 当前framework不能识别IE10版本,把该浏览器做降级处理 ...

  3. .Net设计模式_开篇

    前言 其实以前看过两次设计模式,现在想来,几乎已经对设计模式没有任何印象,说明根本没有理解.或者说几乎不用,所以我除了单列.工厂外的设计模式几乎全部忘记了.最近需要写一个引擎,想用UML设计整体的架构 ...

  4. ASP.NET MVC- 布署

    IIS6.0 1. 安装Microsoft .net FrameWork 4.0安装包; 2. 安装ASP.NET MVC 3; 3. 设置“Web扩展服务”中的“ASP.NET v4.0.0.303 ...

  5. AngularJS开发下一代Web应用笔记(一)

    一.写在最前 AngularJS是Google推出的一款Web应用开发框架.它提供了一系列兼容性良好并且可扩展的服务,包括数据绑定.DOM操作.MVC设计模式和模块加载等. 现在网上JS框架茫茫多,真 ...

  6. NPIV介绍

    我们知道在存储区域网络(SAN:storage area network),主机(Host)能够访问后端存储(比如CLARiiON,VNX)必备的一个前提是主机必须配备HBA卡(Host Bus Ad ...

  7. HDU 3259 Wormholes

    题意:就是给你一个n,m,t   n代表有多少个点.m代表有多少个双向的边  t代表的是虫洞.如今要你判读是否还能够穿越到过去的点 虫洞的意思是给你的边是单向的,而且是负权值(输入的时候是正数) 思路 ...

  8. centos 5.4 安装nodejs + npm(转)

    而在安装nodejs的时候,需要用到,所以需要手动安装bz2库. sudo yum install -y bzip2* cd Python-/Modules/zlib ./configure make ...

  9. css z-index详解

    写css z-index的时候经常会出现很多莫名其妙的问题,下面对z-index属性做彻底的剖析,本文参考了<一个css中z-index的用法>,并做了很多demo,方便了解z-index ...

  10. Andriod:如何卸载模拟器上已经安装的应用程序?

    根据学习对HelloWorld进行手术的时候,遇到了一个问题: 就是在修改了布局后,重新链接模拟器时报错: Installing helloworld.apk... Re-installation f ...