Educational Codeforces Round 47
A. Game Shopping
签.
#include <bits/stdc++.h>
using namespace std; #define N 1010
int n, m, c[N];
queue <int> q; int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
while (!q.empty()) q.pop();
for (int i = ; i <= n; ++i) scanf("%d", c + i);
for (int i = , x; i <= m; ++i)
{
scanf("%d", &x);
q.push(x);
}
int res = ;
for (int i = ; i <= n && !q.empty(); ++i)
{
if (q.front() >= c[i])
{
q.pop();
++res;
}
}
printf("%d\n", res);
}
return ;
}
B. Minimum Ternary String
签.
#include <bits/stdc++.h>
using namespace std; #define N 100010
char s[N];
int n, cnt; int main()
{
while (scanf("%s", s + ) != EOF)
{
n = strlen(s + );
cnt = ;
for (int i = ; i <= n; ++i) if (s[i] == '')
++cnt;
bool flag = false;
for (int i = ; i <= n; ++i)
{
if (flag && s[i] != '')
putchar(s[i]);
else if (!flag)
{
if (s[i] == '')
putchar(s[i]);
else if (s[i] == '')
{
flag = true;
while (cnt--) putchar('');
putchar(s[i]);
}
}
}
if (cnt > ) while (cnt--) putchar('');
puts("");
}
return ;
}
C. Annoying Present
签.
#include <bits/stdc++.h>
using namespace std; #define db long double
#define ll long long
#define N 100010
int n, m, x[N], d[N]; ll f(int x)
{
return 1ll * n * (n + ) / + (1ll * x * x - 1ll * n * x - x);
} int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
ll Max = (ll)-1e18, Min = (ll)1e18;
for (int i = ; i <= n; ++i)
{
ll tmp = f(i);
Max = max(Max, tmp);
Min = min(Min, tmp);
}
for (int i = ; i <= m; ++i)
scanf("%d%d", x + i, d + i);
db res = ;
for (int i = ; i <= m; ++i)
{
res += 1ll * n * x[i];
if (d[i] < )
res += 1ll * d[i] * Min;
else
res += 1ll * d[i] * Max;
}
printf("%.10Lf\n", res * 1.0 / n);
}
return ;
}
D. Relatively Prime Graph
签。
$考虑质数的密度很大 并且\phi(p) = p - 1 所以暴力找边即可$
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 100010
#define pii pair <int, int>
int n, m;
vector <pii> res;
int phi[N], prime[N];
bool check[N];
int tot; void init()
{
memset(check, false, sizeof check);
phi[] = ;
tot = ;
for (int i = ; i < N; ++i)
{
if (!check[i])
{
prime[++tot] = i;
phi[i] = i - ;
}
for (int j = ; j <= tot; ++j)
{
if (i * prime[j] >= N) break;
check[i * prime[j]] = true;
if (i % prime[j] == )
{
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else
phi[i * prime[j]] = phi[i] * (prime[j] - );
}
}
} int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main()
{
init();
while (scanf("%d%d", &n, &m) != EOF)
{
ll sum = ;
for (int i = ; i <= n; ++i) sum += phi[i];
if (m < n - || m > sum)
{
puts("Impossible");
continue;
}
puts("Possible");
for (int i = ; i <= n; ++i) printf("%d %d\n", , i);
m -= n - ;
vector <int> vec;
for (int i = ; i <= n; ++i) vec.push_back(i);
sort(vec.begin(), vec.end(), [](int a, int b) { return phi[a] > phi[b]; });
for (auto it : vec)
{
for (int i = ; i < it && m > ; ++i) if (gcd(it, i) == )
{
printf("%d %d\n", it, i);
--m;
}
if (m <= ) break;
}
}
return ;
}
E. Intercity Travelling
签。
统计$a_i$被计算多少次
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 1000010
const ll p = (ll);
int n;
ll a[N], Bit[N]; int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%lld", a + i);
Bit[] = ;
for (int i = ; i <= n; ++i) Bit[i] = (Bit[i - ] * ) % p;
if (n == )
{
printf("%lld\n", a[]);
continue;
}
ll res = ;
for (int i = ; i <= n; ++i)
{
res = (res + Bit[n - i] * a[i] % p) % p;
if (n - i - >= )
res = (res + 1ll * (n - i) * Bit[n - i - ] % p * a[i] % p) % p;
}
printf("%lld\n", res);
}
return ;
}
Educational Codeforces Round 47的更多相关文章
- Educational Codeforces Round 47 (Rated for Div. 2) 题解
		题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ... 
- Educational Codeforces Round 47 (Div 2) (A~G)
		目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ... 
- Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling
		题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ... 
- Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph
		题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ... 
- Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)
		题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ... 
- Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String
		题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ... 
- Educational Codeforces Round 47 (Rated for Div. 2) :A. Game Shopping
		题目链接:http://codeforces.com/contest/1009/problem/A 解题心得: 题意就是给你两个数列c,a,你需要从c中选择一个子串从a头开始匹配,要求子串中的连续的前 ... 
- cordforce Educational Codeforces Round 47 补题笔记 <未完>
		题目链接 http://codeforces.com/contest/1009 A. Game Shopping 直接模拟即可,用了一个队列来存储账单 #include <iostream> ... 
- Educational Codeforces Round 47 (Rated for Div. 2)E.Intercity Travelling
		题目链接 大意:一段旅途长度N,中间可能存在N-1个休息站,连续走k长度时,疲劳值为a1+a2+...+aka_1+a_2+...+a_ka1+a2+...+ak,休息后a1a_1a1开始计, ... 
- Educational Codeforces Round 47 (Rated for Div. 2)F. Dominant Indices 线段树合并
		题意:有一棵树,对于每个点求子树中离他深度最多的深度是多少, 题解:线段树合并快如闪电,每个节点开一个权值线段树,递归时合并即可,然后维护区间最多的是哪个权值,到x的深度就是到根的深度减去x到根的深度 ... 
随机推荐
- Android中Invalidate与postInvalidate的区别<转>
			http://www.cnblogs.com/it-tomorrow/archive/2012/11/08/2760146.html 示例:http://rayleung.iteye.com/blog ... 
- 安装DatabaseLibrary
			Using pip pip install robotframework-databaselibrary From Source Download source from https://github ... 
- Serlvet学习笔记之一 ——实现servlet的3种方法
			1.配置环境,从tomcat的lib下面引入servlet-api.jar包. 
- mac 操作idea快捷键
			http://blog.csdn.net/rainytooo/article/details/51469126 在mac下idea的常用快捷键如下,下面的快捷键都亲自试用,并有一些和eclipse对比 ... 
- OAuth2认证有一定的了解
			转到分享界面后,进行OAuth2认证: 以新浪为例: 第一步.WebView加载界面,传递参数 使用WebView加载登陆网页,通过Get方法传递三个参数:应用的appkey.回调地址和展示方式dis ... 
- php检测文件只读、可写、可执行权限
			例子:检测文件是否可读.可写.可执行. 复制代码代码示例: <?php $myfile = "./test.txt"; if (is_readable ($myfile)) ... 
- 怎样使用es6 export,import不会报错
			如果浏览器支持es6的话,需要加上type="module" <script type="module"> import Store from &q ... 
- ajax返回值传给js全局变量
			1. $.ajaxSetup({ async : false //设置ajax为同步方式,异步方式的话在赋值时数据还未提取出来 });var t = ""; var enginee ... 
- cursor:hand & cursor:pointer
			1.cursor:hand & cursor:pointer都是将鼠标设置为手形. 2.cursor:hand存在兼容性问题,firefox并不支持该属性值.但大部分主流浏览器支持cursor ... 
- Excel ALT+小键盘的妙用
			用法就是摁住ALT不松,然后输入小键盘数字(一定要小键盘),再松开ALT就可以了 α ALT+42689β ALT+42690γ ALT+42691δ ALT+4269 ... 
