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的更多相关文章

  1. Educational Codeforces Round 47 (Rated for Div. 2) 题解

    题目链接:http://codeforces.com/contest/1009 A. Game Shopping 题目: 题意:有n件物品,你又m个钱包,每件物品的价格为ai,每个钱包里的前为bi.你 ...

  2. Educational Codeforces Round 47 (Div 2) (A~G)

    目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...

  3. Educational Codeforces Round 47 (Rated for Div. 2) :E. Intercity Travelling

    题目链接:http://codeforces.com/contest/1009/problem/E 解题心得: 一个比较简单的组合数学,还需要找一些规律,自己把方向想得差不多了但是硬是找不到规律,还是 ...

  4. Educational Codeforces Round 47 (Rated for Div. 2) :D. Relatively Prime Graph

    题目链接:http://codeforces.com/contest/1009/problem/D 解题心得: 题意就是给你n个点编号1-n,要你建立m条无向边在两个互质的点之间,最后所有点形成一个连 ...

  5. Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)

    题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...

  6. Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String

    题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...

  7. Educational Codeforces Round 47 (Rated for Div. 2) :A. Game Shopping

    题目链接:http://codeforces.com/contest/1009/problem/A 解题心得: 题意就是给你两个数列c,a,你需要从c中选择一个子串从a头开始匹配,要求子串中的连续的前 ...

  8. cordforce Educational Codeforces Round 47 补题笔记 <未完>

    题目链接 http://codeforces.com/contest/1009 A. Game Shopping 直接模拟即可,用了一个队列来存储账单 #include <iostream> ...

  9. 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​开始计, ...

  10. Educational Codeforces Round 47 (Rated for Div. 2)F. Dominant Indices 线段树合并

    题意:有一棵树,对于每个点求子树中离他深度最多的深度是多少, 题解:线段树合并快如闪电,每个节点开一个权值线段树,递归时合并即可,然后维护区间最多的是哪个权值,到x的深度就是到根的深度减去x到根的深度 ...

随机推荐

  1. glob模块--查询一个文件名列表

    ''' 在python中,glob模块是用来查找匹配的文件的 在查找的条件中,需要用到Unix shell中的匹配规则: * : 匹配所所有 ? : 匹配一个字符 *.* : 匹配如:[hello.t ...

  2. ELK5.X+logback搭建日志平台

    一.背景 当生产环境web服务器做了负载集群后,查询每个tomcat下的日志无疑是一件麻烦的事,elk为我们提供了快速查看日志的方法. 二.环境 CentOS7.JDK8.这里使用了ELK5.0.0( ...

  3. <转>Logistic回归总结

    转自http://blog.csdn.net/dongtingzhizi/article/details/15962797 当我第一遍看完台大的机器学习的视频的时候,我以为我理解了逻辑回归,可后来越看 ...

  4. jQuery stop()的用法

    1.stop([stopAll], [gotoEnd])方法有两个参数(当然可以不传或直传一个),其中stopAll的意思是清除之后的所有动画.gotoEnd的意思是,执行完当前动画. 2.stopA ...

  5. 【BZOJ2300】[HAOI2011]防线修建 set维护凸包

    [BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...

  6. 【Wannafly挑战赛4】F 线路规划 倍增+Kruskal+归并

    [Wannafly挑战赛4]F 线路规划 题目描述 Q国的监察院是一个神秘的组织.这个组织掌握了整个帝国的地下力量,监察着Q国的每一个人.监察院一共有N个成员,每一个成员都有且仅有1个直接上司,而他只 ...

  7. dubbo用途介绍

    转自:http://blog.csdn.net/wuliu_forever/article/details/52053928 我们讨论过Nginx+tomcat组成的集群,这已经是非常灵活的集群技术, ...

  8. (java部署篇)eclipse ~ 自动补全词的各种控制(转)

    #这种方法只适用于Eclipse Classic版本(这个版本带有插件的源码) 在使用Eclispe的过程,感觉自动补全做的不好,没有VS的强大.下面说两个增强自动补全的方法: 1.增加Eclipse ...

  9. JS判断当前是否是IE浏览器,并返回时IE几?

    原文参考: https://www.cnblogs.com/liuyanxia/p/5855760.html 具体代码示例: 这里返回的是:如果不是IE浏览器返回 -1 ,返回 7/8/9/10/11 ...

  10. try...finally的妙用

    受博文 C#中Finally的一个不太常见的用法 的启发,正好在开发中遇到这样一段代码: public bool ChangeBlogApp(Guid userID, string oldBlogAp ...