Codeforces Round #257 (Div. 2) 题解
A. Jzzhu and Children
1 second
256 megabytes
standard input
standard output
There are n children in
Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n.
The i-th child wants to get at least ai candies.
Jzzhu asks children to line up. Initially, the i-th
child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
- Give m candies to the first child of the line.
- If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).
Output a single integer, representing the number of the last child.
5 2
1 3 1 4 2
4
6 4
1 1 2 2 3 3
6
传送门:点击打开链接
解体思路:简单模拟题,用队列模拟这个过程就可以。
代码:
#include <cstdio>
#include <queue>
using namespace std; typedef pair<int, int> P;
queue<P> q; int main()
{
#ifndef ONLINE_JUDGE
freopen("257Ain.txt", "r", stdin);
#endif
int n, m, ans = 0;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
q.push(P(x, i + 1));
}
while(!q.empty())
{
P p = q.front(); q.pop();
if(p.first > m)
{
p.first -= m;
q.push(p);
}
ans = p.second;
}
printf("%d\n", ans);
return 0;
}
Problem B
1 second
256 megabytes
standard input
standard output
Jzzhu has invented a kind of sequences, they meet the following property:
You are given x and y,
please calculate fn modulo 1000000007 (109 + 7).
The first line contains two integers x and y (|x|, |y| ≤ 109).
The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output a single integer representing fn modulo 1000000007 (109 + 7).
2 3
3
1
0 -1
2
1000000006
传送门:点击打开链接
解体思路:简单数学公式的推导,
f(n) = f(n-1) + f(n+1), f(n+1) = f(n) + f(n+2);
两式相加得:f(n-1) + f(n+2) = 0,
由上式可推得:f(n+2) + f(n+5) = 0;
由上两式得:f(n-1) = f(n+5),所以f(n)的周期为6;
我们仅仅需求出f的前六项就可以,ps:注意一点,f(n)可能为负值,对负数取模要先对负数加mod,使负数变为正数之后再取模。
代码:
#include <cstdio> const int mod = 1000000007; int main()
{
#ifndef ONLINE_JUDGE
//freopen("257Bin.txt", "r", stdin);
#endif
int n, a [7];
scanf("%d%d%d", &a[0], &a[1], &n);
for(int i = 2; i < 7; i++)
a[i] = a[i - 1] - a[i - 2];
int t = a[(n - 1)% 6];
printf("%d\n", t >= 0 ? t % mod : (t + 2 * mod) % mod);
return 0;
}
Problem C
1 second
256 megabytes
standard input
standard output
Jzzhu has a big rectangular chocolate bar that consists of n × m unit
squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical);
- each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
- each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 × 6 chocolate
for 5 times.
Imagine Jzzhu have made k cuts
and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts?
The area of a chocolate piece is the number of unit squares in it.
A single line contains three integers n, m, k (1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times,
print -1.
3 4 1
6
6 4 2
8
2 3 4
-1
传送门:点击打开链接
解体思路:
n行m列,在水平方向最多切n-1刀,竖直方向最多切m-1刀,假设k>n+m-2,就是不能分割的情况;我们找出沿水平方向或竖直方向能够切的最多的刀数mx,假设k>mx,我们就如今这个方向切mx刀,剩下的就是要将一条长为(mn+1)巧克力切(k - mx)刀;其它的情况就是要么就是沿着水平方向切k刀,要么就是沿着竖直方向切k刀,取两者间的大者。
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; int main()
{
int n, m, k;
long long ans = -1;
cin >> n >> m >> k;
if(k > n + m -2)
ans = -1;
else
{
int mx = max(n - 1, m - 1);
int mn = min(n - 1, m - 1);
if(k > mx)
ans = (mn + 1) / (k - mx + 1);
else
ans = max(1ll * n / (k + 1) * m, 1ll * m / (k + 1) * n);
}
cout << ans << endl;
return 0;
}
Codeforces Round #257 (Div. 2) 题解的更多相关文章
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
随机推荐
- 超声波模块SRF05
//////////////////////////////////////////////////////////////////////////////// // // PIC16F877 ...
- iotop 分析系统那些进程占用io资源
iotop -b -o -t -qqq >> /tmp/iotop.log 1.直接yum安装,rh6的光盘里有包. yum install iotop 2.命令参数介绍 -o ...
- python 多线程一(lock)
''' Created on Jun 17, 2013 @author: smp ''' #-*- coding:utf-8 -*- import threading import time coun ...
- 14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新:
14.4.3.5 Configuring InnoDB Buffer Pool Flushing 配置InnoDB Buffer Pool 刷新: InnoDB执行某些任务在后台, 包括flush 脏 ...
- 爬虫总结_python
import sqlite3 Python 的一个非常大的优点是很容易写很容易跑起来,缺点就是很多不那么著名的(甚至一些著名的)程序和库都不像 C 和 C++ 那边那样专业.可靠(当然这也有动态类型 ...
- hibernate学习(二)
hibernate 单向一对多映射 一.数据表设计 数据库名:hibernate5 数据表: ①表名:CUSTOMERS 字段: CUSTOMER_ID CUSTOMER_NAME ②表名:ORDE ...
- ps中图层混合模式算法公式
网上已经有很多讲解ps的图层混合模式,有些不详细甚至是错误的,参考网上给出的公式及其自己在验证推倒的,给出27种的混合模式算法公式.也许存在一定的错误性,毕竟没有官方给出公式,只能说以供参考吧. 只考 ...
- Storm集群中执行的各种组件及其并行
一.Storm中执行的组件 我们知道,Storm的强大之处就是能够非常easy地在集群中横向拓展它的计算能力,它会把整个运算过程切割成多个独立的tasks在集群中进行并行计算.在Storm中 ...
- freemark换行输出
<!--附件图片--> <#if attatList? exists> <#if (attatList?size>0)> ...
- 分布式发布订阅消息系统Kafka
高吞吐量的分布式发布订阅消息系统Kafka--安装及测试 一.Kafka概述 Kafka是一种高吞吐量的分布式发布订阅消息系统,它可以处理消费者规模的网站中的所有动作流数据. 这种动作(网页浏览, ...