比赛链接:http://codeforces.com/contest/569

A. Music
time limit per test:2 seconds
memory limit per test:256 megabytes

Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.

Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration isT seconds. Lesha
downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone,
and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. Forq seconds of real time the Internet allows you to downloadq - 1
seconds of the track.

Tell Lesha, for how many times he will start the song, including the very first start.

Input

The single line contains three integers
T, S, q (2 ≤ q ≤ 104,1 ≤ S < T ≤ 105).

Output

Print a single integer — the number of times the song will be restarted.

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

In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds,
the song is downloaded completely, and thus, Lesha starts the song twice.

In the second test, the song is almost downloaded, and Lesha will start it only once.

In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.

题目大意:一个人下载歌,每q个时间单位能下载q-1个时间单位的歌,歌的长度为T。下到S的时候開始播放,假设歌还没下完且放到了还未下载的地方。则重头開始放,问一共要放多少次

题目分析:一開始从s開始。设下了cur秒后听和下的进度同样,则 s + (q - 1) / q * cur = cur,解得cur = q * s,然后从头開始。设t'秒后进度同样,则(q - 1) / q * t' + cur = t'。解得t' = cur * q,可见直接拿第一次进度同样的时间乘q就是接下来每次进度同样的时间

#include <cstdio>

int main()
{
int T, S, q, ans = 1, cur;
scanf("%d %d %d", &T, &S, &q);
cur = q * S;
while(cur < T)
{
cur = q * cur;
ans ++;
}
printf("%d\n", ans);
}
B. Inventory
time limit per test:1 second
memory limit per test:256 megabytes

Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers
and keep the track of everything.

During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the
items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.

You have been given information on current inventory numbers forn items in the company. Renumber items so that their inventory numbers form apermutation
of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set ofn numbers forms a
permutation if all the numbers are in the range from
1 to n, and no two numbers are equal.

Input

The first line contains a single integer
n — the number of items (1 ≤ n ≤ 105).

The second line contains n numbersa1, a2, ..., an
(1 ≤ ai ≤ 105) — the initial inventory numbers of the items.

Output

Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.

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

In the first test the numeration is already a permutation, so there is no need to change anything.

In the second test there are two pairs of equal numbers, in each pair you need to replace one number.

In the third test you need to replace
2 by 1, as the numbering should start from one.

题目大意:给n个数,能够改变随意个数字的大小目标是将其改成1-n的一个排列,要求改变次数最小,输出排列

题目分析:记录原始序列已经在1-n位置的数,凡是大于n的或者反复出现的数字下标 标记一下。枚举一下1-n中还有哪些数字没出现。然后按顺序改动

#include <cstdio>
#include <cstring>
int const MAX = 1e5 + 5;
int a[MAX], need[MAX];
bool has[MAX], pos[MAX]; int main()
{
int n, num = 0;
scanf("%d", &n);
memset(has, false, sizeof(has));
memset(pos, false, sizeof(pos));
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if(!has[a[i]] && a[i] <= n)
has[a[i]] = true;
else
pos[i] = true;
}
int cnt = 0;
for(int i = 1; i <= n; i++)
if(!has[i])
need[cnt ++] = i;
int idx = 0;
for(int i = 0; i < n; i++)
if(pos[i])
a[i] = need[idx ++];
for(int i = 0; i < n - 1; i++)
printf("%d ", a[i]);
printf("%d\n", a[n - 1]);
}

C. Primes or Palindromes?

time limit per test:3 seconds
memory limit per test:256 megabytes

Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable
properties. Help Rikhail to convince the scientific community in this!

Let us remind you that a number is called
prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.

Rikhail calls a number a
palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.

One problem with prime numbers is that there are too many of them. Let's introduce the following notation:π(n) — the number of primes no larger thann,
rub(n) — the number of palindromic numbers no larger thann. Rikhail wants to prove that there are a lot more primes than palindromic ones.

He asked you to solve the following problem: for a given value of the coefficientA find the maximum
n, such that π(n) ≤ A·rub(n).

Input

The input consists of two positive integers
p, q, the numerator and denominator of the fraction that is the value ofA ().

Output

If such maximum number exists, then print it. Otherwise, print"Palindromic tree is better than splay tree" (without the quotes).

Sample test(s)
Input
1 1
Output
40
Input
1 42
Output
1
Input
6 4
Output
172

题目大意:π(n) 为不大于n的素数个数,rub(n)为不大于n的回文数个数,A=p/q,如今要求最大的n,使得π(n) ≤ A·rub(n)



题目分析:预处理这两类数的个数,数组尽量往大了开吧,1e7过了

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
int const MAX = 1e7 + 5;
int cntpr[MAX], cntpa[MAX], p[MAX];
bool prime[MAX]; void get_prime()
{
int pnum = 1;
memset(cntpr, 0, sizeof(cntpr));
memset(prime, true, sizeof(prime));
for(int i = 2; i <= MAX; i++)
{
cntpr[i] = cntpr[i - 1];
if(prime[i])
{
cntpr[i] ++;
p[pnum ++] = i;
}
for(int j = 1; j <= pnum && i * p[j] < MAX; j++)
{
prime[i * p[j]] = false;
if(i % p[j] == 0)
break;
}
}
} bool judge(int x)
{
char s[10];
sprintf(s, "%d", x);
int len = strlen(s);
for(int i = 0; i < len / 2; i++)
if(s[i] != s[len - i - 1])
return false;
return true;
} void get_palindromes()
{
memset(cntpa, 0, sizeof(cntpa));
for(int i = 1; i <= MAX; i++)
{
cntpa[i] = cntpa[i - 1];
if(judge(i))
cntpa[i] ++;
}
} int main()
{
bool flag = false;
int p, q;
int ans = 0;
get_prime();
get_palindromes();
scanf("%d %d", &p, &q);
for(int i = 1; i <= MAX; i++)
{
if((ll) q * cntpr[i] <= (ll) p * cntpa[i])
{
ans = max(ans, i);
flag = true;
}
}
if(flag)
printf("%d\n", ans);
else
printf("Palindromic tree is better than splay tree\n");
}
D. Symmetric and Transitive
time limit per test:1.5 seconds
memory limit per test:256 megabytes

Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers
is an equivalence relation.

A set ρ of pairs (a, b) of elements of some setA is called a binary relation on set
A. For two elements
a and b of the set
A we say that they are in relationρ, if pair
, in this case we use a notation.

Binary relation is equivalence relation, if:

  1. It is reflexive (for any a it is true that);
  2. It is symmetric (for any a,
    b it is true that if , then);
  3. It is transitive (if and,
    than).

Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":

Take any two elements, a and
b. If , then
(according to property (2)), which means (according to property (3)).

It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.

Here's your task: count the number of binary relations over a set of size
n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).

Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by109 + 7.

Input

A single line contains a single integer n(1 ≤ n ≤ 4000).

Output

In a single line print the answer to the problem modulo
109 + 7.

Sample test(s)
Input
1
Output
1
Input
2
Output
3
Input
3
Output
10
Note

If n = 1 there is only one such relation — an empty one, i.e.. In other words,
for a single elementx of set
A the following is hold:.

If n = 2 there are three such relations. Let's assume that setA consists of two elements,
x and y. Then the valid relations are,ρ = {(x, x)},
ρ = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations.

题目大意:学过离散数学的同学理解起题意更快,求1到n,n个元素组成的集合中,满足对称性和传递性但不满足自反性的二元组关系集合的个数



题目分析:先结束下例子3,能够是

空集

{<a, a>}, {<b, b>},{<c, c>}

{<a, a>, <b, b>},{<a, a>, <c, c>},{<b, b>, <c, c>}

{<a, a>, <b, b>, <a, b>, <b, a>},{<b, b>, <c, c>, <b, c>, <c, b>},{<a, a>, <c, c>, <a, c>, <c, a>} 一共10个

由于每组等价关系的个数正好等于Bell数,所以不难推出ans[i] = Bell[i + 1] - Bell[i]。从下一个等价关系个数中减去从当前等价关系推出的个数即为当前不满足自反的二元组关系个数,直接推Bell三角形就可以

#include <cstdio>
#define ll long long
int const MAX = 4005;
int const MOD = 1e9 + 7;
ll dp[MAX][MAX]; int main()
{
int n;
scanf("%d", &n);
dp[0][0] = 1;
for(int i = 1; i <= n; i++)
{
dp[i][0] = dp[i - 1][i - 1];
for(int j = 1; j <= i; j++)
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % MOD;
}
printf("%I64d\n", dp[n][n - 1]);
}

Codeforces Round #315 (Div. 2) (ABCD题解)的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. # Codeforces Round #529(Div.3)个人题解

    Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...

  3. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  4. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  5. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  6. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  7. Codeforces Round #538 (Div. 2) (A-E题解)

    Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...

  8. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  9. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

随机推荐

  1. javafx clipboard

    public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...

  2. 2017国家集训队作业[agc006e]Rotate 3x3

    2017国家集训队作业[agc006e]Rotate 3x3 题意: ​ 给你一个\(3*N\)的网格,每次操作选择一个\(3*3\)的网格,旋转\(180^\circ\).问可不可以使每个位置\(( ...

  3. sessionStorage的使用方法

    本篇是关于sessionStorage的使用方法的介绍,简单几行代码,实现sessionStorage,请大家查阅 (1)在需要设置sessionStorage的页面写如下代码可以存入sessionS ...

  4. myBatis通过逗号分隔字符串,foreach

    前言 当数据库里存储的值是以逗号分隔格式存储的字符串时. 数据格式如下:  id name  ids   1  张三  a,b,c  2  李四  c,d,e 我们拿到的条件参数是:b,e 1.后台通 ...

  5. 【Django】缓存

    由于Django是动态网站,所以每次请求都会去数据库中进行响应的操作. 当程序访问量大时,耗时必然会更加明显,最简单的解决方案就是使用缓存. Django中的缓存: ==即将某一个view的返回值保存 ...

  6. python stomp activemq客户端

    #coding=utf-8import timeimport sysimport stomp class MyListener(object): def on_error(self, headers, ...

  7. Android使用BroadCastRecevier广播实现接收短信,并利用Toast弹出显示内容

    在上一篇文章 Android简单实现BroadCastReceiver广播机制 中简单的实现了一个广播机制,这里利用BroadCarstRecevier实现一个接收短信并显示内容的案例,当然至于接收到 ...

  8. elasticsearch java 客户端之action简介

    上一篇介绍了elasticsearch的client结构,client只是一个门面,在每个方法后面都有一个action来承接相应的功能.但是action也并非是真正的功能实现者,它只是一个代理,它的真 ...

  9. 关于结构体COORD介绍

    COORD是windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标.其定义为: typedef struct _COORD { SHORT X; // horizontal coor ...

  10. dataguard主备延迟多长时间的查询方法

    select value from v$dataguard_stats where name='apply lag';