Codeforces Round #315 (Div. 2)
这次可以说是最糟糕的一次比赛了吧, 心没有静下来好好的去思考, 导致没有做好能做的题。
Problem_A:
题意:
你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的地方时, 就会重头听, 直到可以听完整首歌,
由于网络堵塞, 你在q秒内只有q-1秒用于下载, 问需要重新多少次, 第一次点击播放也算。
思路:
由题意可知, 下载速度为(q - 1) / q , 假设t秒后听歌的进度和下载的进度一样, 即听到没有下载的地方or已经下载完。
可以得到方程:
(q - 1) / q * t + s = t
化简得:t / q = (t - s) / (q - 1)
求解得:t = q * s
即此时进度为t, 当t >= T时, 即下载完, 模拟即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define MAXM 100
#define dd cout<<"debug"<<endl
#define p(x) printf("%d\n", x)
#define pd(x) printf("%.7lf\n", x)
#define k(x) printf("Case %d: ", ++x)
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define mes(x, d) memset(x, d, sizeof(x))
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int T, S, q; int main()
{
scanf("%d %d %d", &T, &S, &q);
int ans = ;
while(S < T)
{
S *= q;
ans ++;
}
printf("%d\n", ans);
return ;
}
Problem_B:
题意:
给一个数n, 再给n个数a[i],a[i]中会有重复 或者大于n的数。
要求你给出一个1~n的排列。
思路:
求一个排列, 那么将不符合的数用符合的数代替即可。
将a[i]中大于n 和 小于等于n 且重复的数的编号index记录下来
然后用1~n中没有出现过的数替换掉即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 100010
#define MAXM 100
#define dd cout<<"debug"<<endl
#define p(x) printf("%d\n", x)
#define pd(x) printf("%.7lf\n", x)
#define k(x) printf("Case %d: ", ++x)
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define mes(x, d) memset(x, d, sizeof(x))
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
int n;
int a[MAXN];
int ans[MAXN];
int ord[MAXN];
bool vis[MAXN]; int main()
{
int x;
int cnt, t;
scanf("%d", &n);
cnt = ;
t = ;
mes(ans, );
mes(ord, );
mes(vis, false);
for(int i = ; i < n; i ++)
{
scanf("%d", &a[i]);
if(vis[a[i]] || a[i] > n) ord[cnt ++] = i;
else if(!vis[a[i]])
vis[a[i]] = true;
}
int k1 = ;
for(int i = ; i <= n; i ++)
if(!vis[i]) a[ord[k1 ++]] = i;
for(int i = ; i < n; i ++)
printf("%d ", a[i]);
printf("\n");
return ;
}
Problem_C:
题意:
给两个数, p, q。 求满足π(n) ≤ A * rad(n) 的n 的最大取值。
π(n)是小于等于n的素数个数, rad(n)是小于等于n的回文数的个数, A = p / q。
思路:
首先, 回文数比较少,200w以内也只有2998个, 而 A 最大为42, 2998 * 42 = 125916
而200W以内的素数有148933个 > 125916, 而越往上, n越大, 素数越来越多, 而且增长幅度大于回文数, 所以, 最大数只能是在200W以内寻找。
将所有的素数和回文数预处理出来, 然后循环寻找最大的n, 复杂度为O(2 * 10 ^ 5), q可以乘过去, 避免处理浮点数。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 2000000
#define MAXM 100
#define dd cout<<"debug"<<endl
#define p(x) printf("%d\n", x)
#define pd(x) printf("%.7lf\n", x)
#define pa {system("pause");}
#define k(x) printf("Case %d: ", ++x)
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define mes(x, d) memset(x, d, sizeof(x))
#define do(i, x) for(i = 0; i < x; i ++)
#define dod(i, x, l) for(i = x; i >= l; i --)
#define doe(i, x) for(i = 1; i <= x; i ++)
bool prime[MAXN];
int pm[MAXN];
int rm[MAXN];
int p, q;
bool is_ok(int n);
void init()
{
prime[] = prime[] = false;
prime[] = true;
for(int i = ; i <MAXN; i ++)
prime[i] = (i % == ? false : true);
int t = (int)sqrt(MAXN * 1.0);
for(int i = ; i <= t; i ++)
if(prime[i])
for(int j = i + i; j < MAXN; j += i)
prime[j] = false;
for(int i = ; i < MAXN; i ++)
{
pm[i] = pm[i -] + (prime[i]? : );
rm[i] = rm[i -] + (is_ok(i)? : );
}
}
bool is_ok(int n)
{
int m = n;
int s = ;
while(m)
{
s = s * + m % ;
m /= ;
}
if(s == n)
return true;
return false;
} int main()
{
init();
while(scanf("%d %d", &p, &q) != EOF)
{
int ans = ;
for(int i = ; i < MAXN; i ++)
if(q * pm[i] <= p * rm[i]) ans = i;
p(ans);
}
return ;
}
Codeforces Round #315 (Div. 2)的更多相关文章
- Codeforces Round #315 (Div. 2) (ABCD题解)
比赛链接:http://codeforces.com/contest/569 A. Music time limit per test:2 seconds memory limit per test: ...
- Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力
A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 ...
- Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力
题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...
- Codeforces Round #315 (Div. 2B) 569B Inventory 贪心
题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...
- Codeforces Round #315 (Div. 2A) 569A Music (模拟)
题目:Click here 题意:(据说这个题的题意坑了不少人啊~~~)题目一共给了3个数---- T 表示歌曲的长度(s).S 表示下载了歌曲的S后开始第一次播放(也就是说S秒的歌曲是事先下载好的) ...
- codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)
题意:求使pi(n)*q<=rub(n)*p成立的最大的n. 先收集所有的质数和回文数.质数好搜集.回文数奇回文就0-9的数字,然后在头尾添加一个数.在x前后加a,就是x*10+a+a*pow( ...
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力
C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #315 (Div. 2) B 水题强行set
B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #315 (Div. 2) A 水且坑
A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
随机推荐
- HDU 4389——X mod f(x)(数位DP)
X mod f(x) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- 将文件的图标添加到LISTVIEW中
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- (求助大牛)关于vs2010上的AVS代码bug问题~~
问题1:就是解码端,出现错误,找到bug所在地了,见下图: memcpy出错了,跳到下图了.可是错误显示的我不懂,求解释一下就ok了,小女子在此谢过了~~哎,调bug的能力弱爆了!! 大家看看吧~~是 ...
- [TypeScript] Configuring TypeScript Which Files to Compile with "Files" and "OutDir"
This lesson shows how to configure the .tsconfig so you only compile the .ts files you want. It then ...
- PureMVC(JS版)源码解析(十二):Facade类
MVC设计模式的核心元素在PureMVC中体现为Model类.View类和Controller类.为了简化程序开发,PureMVC应用Facade模式. Facade是Model\View\Co ...
- (转载)MyEclipse github
最近Git火得如日中天,而且速度体验和团队模式都很不错.手头正好有个学生实训项目,时间紧任务重,而且学校内网管理太紧,所以就想借助于Internet的分布式开发,因此想到了Github. ...
- Android 指定日期时间执行任务的Timer
放上一个指定详细日期及时间的timer public class MainActivity extends Activity { private Handler handler = new Handl ...
- BrainTree信用卡包
BrainTree是一个国外集成信用卡支付的卡包. 沙盒登陆地址: https://sandbox.braintreegateway.com/login 登陆沙盒得到商户ID.公钥.私钥. 1.配置w ...
- angularJs 使用中遇到的问题小结【一:关于传参】
我请教个问题 :我在界面传了一个参数<a ng-click="deleteOrder({{orderOrder}})" class="btn warning-btn ...
- jquery判断div是否显示或者隐藏
jquery判断div是否显示或者隐藏 很多时候会要判断一个div是不是显示着,没显示要怎么处理,显示的如何处理: 方法很简单,选择到你要判断的div,再用is(':hidden')判断是否隐藏:或者 ...