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到根的深度 ...
随机推荐
- Swift - UITableView的用法
因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...
- Effective C++ —— 资源管理(三)
条款13 : 以对象管理资源 假设有如下代码: Investment* createInvestment(); //返回指针,指向Investment继承体系内的动态分配对象,调用者有责任删除它 vo ...
- 将display设置为inline-block之后产生间隙然后换行问题的解决方法
在我们会用display的时候,inline-block肯定不陌生吧,我今天在做项目的时候,用了inline-block,使a标签可以自定义宽度,但是随之而来的问题就是换行的BUG,如下图 特地加了一 ...
- MITE
.,text/html .,text/h323 .aaf,application/octet-stream .aca,application/octet-stream .accdb,applicati ...
- 原生JS,实现图片可拖拽,并且移动四个角和四条变能够自由变换图片大小
网上搜的资料,源码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- javascript关于链接的一些用法
(1)javascript:openURL() http://www.kpdown.com/search?name=Ben Nadel 此URL后边有一个name参数,只不过参数的值竟然带了空格,这样 ...
- jquery.js与sea.js综合使用
jquery.js与sea.js综合使用 目录 模块定义 define id dependencies factory exports require require.async require. ...
- 什么是真正的APM?
近年来APM行业被越来越多的企业所关注,尤其是在2014年末,NewRelic的成功上市,更加激发了人们对这个行业前景的无限遐想.那么究竟什么是APM?APM的目的是什么?要求我们做什么?有不少企业对 ...
- OC开发_Storyboard——block和动画
一.协议 @optional :可选的 @requied :必须实现的 二.block 代码块 1. 以一个^开头,然后是参数,然后是一个大括号,包含我们的代码块 [aDictionary enu ...
- 次小生成树(poj1679)
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20737 Accepted: 7281 D ...