Codeforces Round #262 (Div. 2) A B C
A. Vasya and Socks
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, ...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers n and m (1 ≤ n ≤ 100; 2 ≤ m ≤ 100), separated by a space.
Print a single integer — the answer to the problem.
- 2 2
- 3
- 9 3
- 13
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
题意 : 初始有n双袜子,妈妈每m天给他买一双袜子,他每天早上穿新袜子,晚上扔掉,问多少天之后他没有袜子穿。
思路 : 我的思路是循环模拟。看了官方解题报告最终答案是n+(n-1)/(m-1).
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- using namespace std ;
- int main()
- {
- int n,m ;
- while(~scanf("%d %d",&n,&m))
- {
- int cnt = ;
- while()
- {
- n -- ;
- if(cnt % m == )
- n ++ ;
- if(n == ) break ;
- cnt ++ ;
- }
- printf("%d\n",cnt) ;
- }
- return ;
- }
B. Little Dima and Equation
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions x (0 < x < 109) of the equation:
x = b·s(x)a + c,
where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.
The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.
The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000; - 10000 ≤ c ≤ 10000).
Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
- 3 2 8
- 3
10 2008 13726
- 1 2 -18
- 0
- 2 2 -1
- 4
1 31 337 967
题意 : 给你abc,找出所有满足这个式子的数x = b·s(x)a + c,其中s(x)代表的是把x的每一位加起来。
思路 :枚举s(x),因为x最大是10^9,所以s(x)最大是81,所以枚举s(x)的时候求出x,判断x的每一位相加是否等于s(x)。
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <string.h>
- #include <algorithm>
- #define LL __int64
- using namespace std ;
- LL sh[] ;
- LL poww(int a,int n)
- {
- LL s = ;
- for(int i = ; i <= n ; i++)
- s *= (LL)a ;
- return s;
- }
- int main()
- {
- int a,b,c ,cnt;
- while(~scanf("%d %d %d",&a,&b,&c))
- {
- cnt = ;
- memset(sh,,sizeof(sh)) ;
- for(int i = ; i <= ; i++)
- {
- LL sum = ,sum1 = ;
- sum1 = b*poww(i,a)+c ;
- LL sum2 = sum1 ;
- while(sum2)
- {
- sum += sum2% ;
- sum2 /= ;
- }
- if(sum == i && sum1 < 1e9)
- sh[cnt ++] = sum1 ;
- }
- printf("%d\n",cnt) ;
- if(cnt)
- {
- for(int i = ; i < cnt- ; i++)
- printf("%I64d ",sh[i]) ;
- printf("%I64d\n",sh[cnt-]) ;
- }
- }
- return ;
- }
C. Present
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output
Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.
There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?
The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the maximum final height of the smallest flower.
- 6 2 3
2 2 2 2 1 1
- 2
- 2 5 1
5 8
- 9
In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.
题意 : n盆花,编号1到n,每盆花都有高度值,还有m天,每天只能浇一次水,且每次浇只能浇连续的w盆花,每浇一次,被浇的花长一个高度值。求怎样浇花,能让其中最矮的花取到最高值。
思路 : 二分+贪心。二分最小值,然后再贪心,二分最小值,然后求出每盆花与最小值的差值,然后从左到右进行扫描,分段浇水,第一盆浇了3次水的花,前w盆的值都相应的减掉3.
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #define LL __int64
- using namespace std;
- LL a[],b[],c[] ;
- int main()
- {
- int n,m,w ;
- while(~scanf("%d %d %d",&n,&m,&w))
- {
- LL low = 1e10 , high = - ,mid,ans = ;
- for(int i = ; i < n ; i ++)
- {
- scanf("%I64d",&a[i]) ;
- low = min(low,a[i]) ;
- high = max(high,a[i]) ;
- }
- high += m ;
- while(low <= high)
- {
- memset(c,,sizeof(c)) ;
- mid = (low+high)/ ;
- for(int i = ; i < n ; i++)
- b[i] = max(0LL,mid-a[i]) ;//用数组b保存每朵花还需要浇水的次数
- LL days = m,sum = ;
- for(int i = ; i < n ; i++)
- {
- sum += c[i] ;
- b[i] -= sum ;//将前边浇连续段已经浇的减掉
- if(b[i] > )
- {
- days -= b[i] ;
- if(days < ) break ;
- sum += b[i] ;//已浇b[i]天;
- c[i+w] -= b[i] ;
- }
- }
- if(days < ) high = mid - ;
- else {
- ans = mid ;
- low = mid+ ;
- }
- }
- printf("%I64d\n",ans) ;
- }
- return ;
- }
Codeforces Round #262 (Div. 2) A B C的更多相关文章
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...
- codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)
题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...
- Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力
E. Roland and Rose Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Round #262 (Div. 2)解题报告
详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks http ...
- Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)
题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...
- Codeforces Round #262 (Div. 2)
A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- Codeforces Round #262 (Div. 2) 二分+贪心
题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...
随机推荐
- memcached 简介
最近,想看看开源的东西,正好在网上看到了memcached这个服务器,就简单学了学.做个笔记! 1.memcached 介绍 memcached我原本以为是一款数据库软件,但详细了解才发现,准确的是一 ...
- Oracle Imp and Exp (导入和导出) 数据 工具使用
Oracle 提供两个工具imp.exe 和exp.exe分别用于导入和导出数据.这两个工具位于Oracle_home/bin目录下. 导入数据exp 1 将数据库ATSTestDB完全导出,用户名s ...
- TCP/IP,HTTP,Socket的区别与联系
一 忆往昔,尽是悔恨泪. 在学校的时候学过,网络七层,也知道tcp的三次握手.但因为根本没用在实际开发中,所以逐渐淡忘.现在就再次理解下三个的区别与联系. 二 正题 网络七层: ...
- Layout Support 获取上下bar的长度
Layout Support This protocol . You can use layout guides as layout items in the NSLayoutConstraint f ...
- iOS Bluetooth Reconnect
蓝牙的重连主要分为以下两种: 1.恢复一些已知的设备,已知的设备就是在此次操作之前你扫描到的或者已经连接过的设备.用retrievePeripheralsWithIdentifiers:函数去完成回复 ...
- 四则运算出题器(C++)-BUG修复
定制题目数量这个功能测试: (1)输入题目数为负数时: 可正确处理: (2)输入题目数量为0时: 可正确处理: (3)输入题目数量为小数时: 程序运行出错: 错误分析: 因为代码中题目数量的变量Que ...
- 项目结队开发---NABC分析(成员)
一.简介 项目名称:校园导航 特点:手机app,简便易用,适合对铁大地形不了解.路痴者使用. 二.NABC分析 N(need):对于新生报到,学生家长参观校园等想要了解校园路线者,本app软件将带给你 ...
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
... 首先了解一下CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Con ...
- IOS常用加密Encryption
NSString+Encryption.h // // NSString+Encryption.h // haochang // // Created by Administrator on 14-4 ...
- C#日志编写
在一个完整的信息系统里面,日志系统是一个非常重要的功能组成部分.它可以记录下系统所产生的所有行为,并按照某种规范表达出来.我们可以使用日志系统所记录的信息为系统进行排错,优化系统的性能,或者根据这些信 ...