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到根的深度 ...
随机推荐
- eclipse不能自动编译XX.java为XX.classs
问题描述:eclipse不能自动编译XX.java为XX.classs 原因:今天下午写代码,因为需要引入jstl包,引入后发现原来项目中已经引入了,然后我又把包删除了,忘记删除java build ...
- Linux tmux 工具
基础术语: sessions :会话,一个用户登录到主机,那么就建立了一个 session,如下图1,详细参考:https://my.oschina.net/u/158589/blog/360862t ...
- 开源项目源码解析-PhotoView 源码解析
1. 功能介绍 特性(Features): 支持 Pinch 手势自由缩放. 支持双击放大/还原. 支持平滑滚动. 在滑动父控件下能够运行良好.(例如:ViewPager) 支持基于 Matrix 变 ...
- Putty的安装和使用
Putty是最简单易用的SSH工具,详细介绍其安装和使用 直接在百度里搜索Putty,可以找到百度软件中心,或者官方网站: PuTTY Download Page. 进入官方网站,直接可执行文件装 ...
- Java中实现多态的机制(实质)?
靠的是父类或接口定义的引用变量可以指向子类或具体实现类的实例对象.
- [置顶] Linux协议栈代码阅读笔记(二)网络接口的配置
Linux协议栈代码阅读笔记(二)网络接口的配置 (基于linux-2.6.11) (一)用户态通过C库函数ioctl进行网络接口的配置 例如,知名的ifconfig程序,就是通过C库函数sys_io ...
- JS-倒计时效果
团购-限时抢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- SenchaTouch调用纯数字键盘
items:[ { itemId:"phoneNumber", xtype: "textfield", component:{xtype:"input ...
- install kubernetes dashboard 安装 kubernetes dashboard 详细
参考: http://www.bubuko.com/infodetail-2242562.html http://www.cnblogs.com/zhenyuyaodidiao/p/6500897.h ...
- Java.lang的研究(分析包含的重要类和接口)
Java.lang包是Java中使用最广泛的一个包,它包含很多定义的类和接口. java.lang包包括以下这些类: Boolean Byte Character Class ClassLoader ...