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到根的深度 ...
随机推荐
- ios iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 转自容芳志大神的博客:http://www.cnblogs.com/stoic/archive/2013/02/27/2940 ...
- MySQL性能优化(三)-- 索引
一.什么是索引及索引的特点 索引是一种数据结构 索引的特点:查找速度快,排好序,数据结构 索引的数据结构类型有:BTREE索引和HASH索引,下面展示的是BTREE索引. BTREE:balance ...
- INSTALL_FAILED_INVALID_APK
在项目中无意中把APP只写成了 xxx 没有xxx.xxx.xxx 掉坑里了,找了好久,给大家提不醒
- MySQL建表字段类型
1.数据库:在MySQL中,要存储数据,必须从数据库开始,因此首先要创建数据库,但由于学校的MySQL服务器对学生数据帐号有限止,学生不得创建数据库,故每个学生的帐号中已事先由信息中心为大家建立了一个 ...
- Android 在界面中显示以及输入文本信息 TextView和EditText
Android控件之TextView和EditTextTextView:显示文本框控件EditText:输入文本框TextView和EditText的常用属性TextView控件的常用属性androi ...
- Oracle分页查询sql语句
1. select * from ( select t.*, rownum RN from TABLE_NAME t ) where RN > 0 and RN <= 15 2. se ...
- 使用WdatePicker获取比当前时间大的写法
<input name="today.date" class="Wdate" type="text" onClick="Wd ...
- Cloud Foundry技术全貌及核心组件分析
原文链接:http://www.programmer.com.cn/14472/ 历经一年多的发展,Cloud Foundry的架构设计和实现有了众多改进和优化.为了便于大家了解和深入研究首个开源Pa ...
- 混合欧拉回路的判断(Dinic)
POJ1637 Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7483 Accepte ...
- SQL取某个字符串最后一次出现的位置后面的字符串方法
--sql怎么取某个字符串最后一次出现的位置后面的字符串 declare @s varchar(max); set @s = 'fj/2016815/2016081553677565.pdf'; se ...