Codeforces Round #315 (Div. 2) (ABCD题)

A. Music

题意:

一首歌长度为S秒,已经下载了T秒,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲。现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次)

思路:

我们可以用路程-时间的思路来考虑这道题。

假设两位选手“播放”与“下载”,“播放”的起点是0m处,“下载”的起点是Tm处,终点在Sm处,“播放”的速度是1m/s,“下载”的速度是(q-1)/q m/s。

假设两名选手在Xm处相遇,那么:

(X-T) / ((q-1)/q)= (X-0)/1

转化下就可得到X = qT。

那么第qT秒就是第一次需要replay的地方。replay以后,T = X,继续计算qT,直到qT > S,累计replay的次数即可。

代码:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;

int main(){
//  freopen("input.txt","r",stdin);
    int t,s,q;
    while(cin >> t >> s >> q){
        int ans = 1;
        int x = s*q;
        while(x < t){
            ans++;
            x = x*q;
        }
        cout << ans << endl;
    }
    return 0;
}

B - Inventory

题意:

把n个数组成的数列变成由1~n组成的数列,1~n每个数只能且必须出现一次。

思路:

map累计每个元素出现次数,再从头扫一遍,出现次数大于1的元素更换为出现次数为0的元素,更新map。

统计下,缺谁补谁呗

代码:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;
map<int,int>mp;
vector<int>q;
int a[100005];
int main(){
//  freopen("input.txt","r",stdin);
    int n;
    while(cin >> n){
        mp.clear();
        q.clear();
        cls(a);
        for(int i = 1 ; i <= n ; i++){
            int tmp;
            scanf("%d",&tmp);
            mp[tmp]++;
            a[i] = tmp;
        }
        for(int i = 1 ; i <= n ; i++){
            if(mp[i] < 1) {
                q.pb(i);
            }
        }
        int k = 0;
        for(int i = 1 ; i <= n ; i++){
            if(mp[a[i]] >= 2 || a[i] > n){
                mp[a[i]]--;
                a[i] = q[k++];
            }
        }
        for(int i = 1 ; i < n ; i++){
            printf("%d ",a[i]);
        }
        printf("%d\n",a[n]);
    }
    return 0;
}

C - Primes or Palindromes?

题意:

定义π(n) = 不大于n的素数个数,

定义rub(n) = 不大于n的回文数个数,

输入p,q(1/42 <= p/q <= 42),求满足π(n) <= p/q * rub(n)的n的最大值。

思路:

你只需要知道,π(n) 的增长速度大于rub(n),打个表看看什么时候π(n) > 42* rub(n),发现大概是n = 2*10^6的时候,再加上3s的时限与cf超越各大oj的机器性能。

枚举大法好。

代码:

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;
const int maxn = 10000000+5;
bool notPrime[maxn+5];

void Prime(void){
    memset(notPrime,false,sizeof(notPrime));
    for(int i = 2; i*i <= maxn; i++){
        if(!notPrime[i]){
            for(int j = i*i; j <= maxn; j += i){
                notPrime[j] = true;
            }
        }
    }
}
int reverse(int n)  {
    int res = 0;
    while(n){
        int d = n % 10;
        res = res*10 + d;
        n /= 10;
    }
    return res;
}
bool hui(int n){
    if(reverse(n) == n) return true;
    return false;
}
vector<int>v;
int main(){
  //freopen("output.txt","w+",stdout);
    int p,q;
    cin >> p >> q;
    Prime();
    lint pr = 0,hu=0;
    v.clear();
    v.pb(1);
    for(int i = 1 ; i <= 10000000; i++){
        if(!notPrime[i] && i!= 1){
            pr++;
        }
        if(hui(i)){
            hu++;
        }
        if(pr * q <= hu*p){
            v.pb(i);
        }
    }
    if(v.size() >= 1){
        cout <<v[v.size()-1] <<endl;
        return 0;
    }
    cout << "Palindromic tree is better than splay tree" << endl;
    return 0;
}

D - Symmetric and Transitive

题意:

求1到n的n个元素组成的二元关系集合中,满足对称性和传递性但不满足自反性的二元组关系集合的个数。

思路:

赛后看到这个题(手速过慢比赛的时候没来得及看),觉得自己的离散数学知识都喂队友了。。

Bell number,又名贝尔数,表示基数为n的集合划分数目,也表示n元素集合的等价关系的数目,于是我们可以发现ans[n] = Bell[n+1] - Bell[n],从下一个等价关系个数中减去从当前等价关系个数,即为当前不满足自反的二元组关系个数。

贝尔数的推导可以用贝尔三角形或第二类斯特林数和。

这个题重在题意理解和样例理解上:

样例1:ρ = ?

样例2:ρ = ? , ρ?=?{(x,?x)} , ρ?=?{(y,?y)}.

样例3:

0个元素(空集):

ρ = ?;

1个元素:

ρ= {(x, x)},ρ= {(y, y)},ρ= {(z, z)};

2个元素:

ρ= {(x, x), (y, y)},ρ= {(x, x), (z, z)},ρ= {(y, y), (z, z)};

3个元素:

无;

4个元素:

ρ= {(x, x), (y, y), (x, y), (y, x)},ρ= {(y, y), (z, z), (y, z), (c, y)},ρ= {(x, x), (z, z), (x, z), (z, x)}

5、6个元素:无

一共10个。

/*
* @author FreeWifi_novicer
* language : C++/C
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>

using namespace std;

#define clr( x , y ) memset(x,y,sizeof(x))
#define cls( x ) memset(x,0,sizeof(x))
#define mp make_pair
#define pb push_back
typedef long long lint;
typedef long long ll;
typedef long long LL;

const int mod = 1e9+7;
const int maxn = 4000 + 5;
lint B[maxn][maxn];
//注释语句可以打印bell三角形
void init(){
    B[1][1] = 1;
    //cout << 1 <<endl;
    for(int i = 2 ; i <= 4001; i++){
        B[i][1] = B[i-1][i-1];
        //cout << B[i][1] << ‘ ‘;
        for(int j = 2 ; j <= i ; j++){
            B[i][j] = (B[i-1][j-1] + B[i][j-1]) % mod;
            //cout << B[i][j] <<‘ ‘;
        }
    }
}
int main(){
    init();
    int n;
    while(cin >> n)
        cout << B[n+1][n] % mod << endl;
    return 0;
}

版权声明:博主表示授权一切转载:)

时间: 2024-10-21 13:28:12

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

Codeforces Round #596 (Div. 2) ABCD题

A题 样例 思路:分情况进行讨论,a比b小1,a和b相等,a为9 b为1的情况 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <string.h> 6 #include <vector> 7 8 using namespace std; 9 10 int main(){ 11

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

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

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov