A. Distance
B. Special Permutation
C. Chat Ban
D.X-Magic Pair
E. Messages
F:没看F,好难的样子
G. Max Sum Array

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5, M = 5e2;int main()
{int t;scanf("%d", &t);while(t --){int a, b;scanf("%d%d", &a, &b);if(abs(a)+abs(b)&1)puts("-1 -1");else{int x = abs(a)>>1, y = (abs(a)+abs(b)>>1)-x;if(a<0)x=-x;if(b<0)y=-y;cout<<x<<' '<<y<<endl;}}return 0;
}

硬模拟

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5, M = 5e2;int main()
{int t;scanf("%d", &t);while(t --){int n, a, b, l = 1, r = 2, pos[N]={0}, nl = 0, nr = 0;bool f = 0;scanf("%d%d%d", &n, &a, &b);for(int i = n;i > b;i --)pos[i] = l, nl++;if(!pos[a])pos[a] = l, nl++;for(int i = 1;i < a;i ++)f |= pos[i] == l, pos[i] = r, nr++;if(!pos[b]) f |= pos[b] == l, pos[b] = r, nr++;for(int i = a+1;i < b;i ++)if(!pos[i]){if(nl < n/2)pos[i] = l, nl++;else pos[i] = r;}if(f || nl!=n/2)puts("-1");else{for(int i = 1;i <= n;i ++)if(pos[i] == l)cout<<i<<' ';for(int i = 1;i <= n;i ++)if(pos[i] == r)cout<<i<<' ';puts("");}}return 0;
}

二分直接算

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5, M = 5e2;LL k, x;bool ch(LL l)
{LL sum = 0;if(l>k) sum = (1+k)*k/2 + (k+2*k-l-1)*(l-k)/2;else sum = (1+l)*l/2;return sum>=x;
}
int main()
{int t;scanf("%d", &t);while(t --){scanf("%lld%lld", &k, &x);LL l = 1, r = 2*k-1;while(l < r){if(ch(mid)) r=mid;else l=mid+1;}cout<<l<<endl;}return 0;
}

队友写的,没搞懂

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5, M = 5e2;int main()
{int t;scanf("%d", &t);while(t --){LL a, b, x;bool f = 0;scanf("%lld%lld%lld", &a, &b, &x);if(x<=max(a, b)){while(a>=x||b>=x&&a&&b){if(a<b)swap(a, b);if(a==x||b==x||(a-x)%b==0){f = 1;break;}a %= b;}}puts(f?"YES":"NO");}return 0;
}

概率公式计算,假设有n张牌,其中里面有他要的,它可以抽k张牌,如果k>n那么这个人的期望就是n/n,否则是1 - (n−1k)\tbinom{n-1}{k}(kn−1​)/(nk)\tbinom{n}{k}(kn​) = k / n。
 然后可以枚举小于20的n枚举的时候k大于n的贡献要变成1。
 对于大于20的n来说答案就可以按照期望贡献对数字排序,再进行递推枚举计算。

具体看代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e5+10, M = 5e2;int a[N][21];
PII b[N];
vector<int>ans;int main()
{int n;scanf("%d", &n);for(int i = 1;i <= n;i ++){int x, y;scanf("%d%d", &x, &y);a[x][y]++;  //有个 数字为x,k等于y的人 }LL ma = 0, mn = 1;   // ma 是最大值, mn是最大值个数其实在ans-vector里有体现; for(int i = 1;i <= 20;i ++){      // 枚举n  for(int j = 1;j <= 2e5;j ++){ // 遍历每个树 int sum = 0;  // 当n等于i时数字i对于期望的贡献 for(int k = 1;k <= i;k ++)sum += a[j][k]*k;  // k < n时 k = k, k ≥n时 k = n;  for(int k = i+1;k <= 20;k ++)sum += a[j][k]*i;b[j] = {-sum, j};   // 第一关键字取反按照从小往大排序的话第一个取反就是最大值; }sort(b+1, b+(int)2e5+1);  LL sum = 0;for(int x = 1;x <= i;x ++)sum += -b[x].first;if(sum*mn>ma*i){   // 分式化乘法 ans.clear();for(int x = 1;x <= i;x ++)ans.push_back(b[x].second);ma = sum; mn = i;}    }LL h = 0;for(int i = 1;i <= 20&&i <= n;i ++)h += -b[i].first;  // 这时候是先求出前二十个的和; for(int i = 21;i <= n;i ++) // 枚举21 - n 的个数取值; {h += -b[i].first;if(h*mn>ma*i)ma = h, mn = i;}if(mn > 20)for(int i = 1;i <= mn;i ++)ans.push_back(b[i].second);cout<<ans.size()<<endl;for(auto x: ans)cout<<x<<' ';cout<<endl;return 0;
}

  没人补G吗,假设有n个相等数字且位置为P1 P2 P3 …Pn,那么你计算之后就可以得到 ∑i=1n\sum_{i=1}^n∑i=1n​ ( 2 ∗\ast∗ i - n -1) ∗\ast∗ Pi

  那么再对于每个n都确定前面的 ( 2 ∗\ast∗ i - n -1),那么这个东西就由 Pi 确定,然后可以看出( 2 ∗\ast∗ i - n -1)要么都是奇数要么都是偶数那么再把不连续的变成连续的(这步在代码里面有注释), 再挨个计算,数量就是( 2 ∗\ast∗ i - n -1)相等的数量的阶乘的乘积

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e6+10, mod = 1e9 + 7;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}LL a[N], b[N], in[N];
// a :-2 0 2 4 6 -> -1 0 1 2 3       n 是奇数
// b :-3 -1 1 3  -> -2  0 2 4 < a    n 是偶数
LL se(LL a, int b){a%=mod;return b*(a+a+b-1)%mod*500000004%mod;}int main()
{int n;scanf("%d", &n);in[0] = 1;for(int i = 1;i <= n;i ++){int x;scanf("%d", &x);LL *t = a, f = 0;if(x%2 == 0)t = b, f = 1;t[(1-x+f)/2+(int)1e6]++;t[(x-1+f)/2+(int)1e6+1]--;in[i] = i*in[i-1]%mod;}int ans = 0, sum = 1;LL head = 1;for(int i = 0;i <= 2e6;i ++){a[i] += a[i-1]; b[i] += b[i-1];add(ans, ((i-(int)1e6)*2-1)*se(head, b[i])%mod);head += b[i];add(ans, ((i-(int)1e6)*2)*se(head,   a[i])%mod);head += a[i];mull(sum, in[b[i]]*in[a[i]]%mod);}add(ans, mod);cout<<ans<<' '<<sum<<endl;return 0;
}

Educational Codeforces Round 117 (Rated for Div. 2)相关推荐

  1. Educational Codeforces Round 117 (Rated for Div. 2)题解(A~D)

    Educational Codeforces Round 117 (Rated for Div. 2) 今天这场没打,赛后从九点半到十一点把前面四个题目给补了一下,E题明天有时间看看能不能弄出来. A ...

  2. Educational Codeforces Round 117 (Rated for Div. 2) ABCDE

    A 题意: 给出A坐标(0,0)和B坐标,d表示两点横纵坐标绝对值之和. 求是否存在C(x,y)满足d(A,C)=d(B,C)=d(A,B)/2,不存在就-1. 思路: d(A,B)直接已知,如果是个 ...

  3. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  4. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  5. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  6. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  7. Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

    Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...

  8. Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs

    传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici​个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环

    传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...

最新文章

  1. mysql主从及读写分离
  2. SystemTap工具的使用基础
  3. python io_python-IO
  4. 【CyberSecurityLearning 31】Linux网络信息查看与配置、日志文件的管理、备份及日志服务器的搭建
  5. chmod、chown函数的使用
  6. 摘抄自知乎的redis相关
  7. 坐地起价、山寨横行、人身骚扰:割韭菜的刀,还是“搬家公司”快
  8. 创建oracle方法,简单的Oracle存储过程的创建方法
  9. php pdo setfetchmode,PDOStatement::setFetchMode
  10. python -m a.py 和 python a.py区别
  11. 神经网络——激活函数的作用
  12. 物联网常用无线模块 接收灵敏度及发射功率简化测量方法
  13. Github删除历史提交记录的方法
  14. python短信验证码_python发送短信验证码
  15. java工厂方法_Java设计模式之工厂方法模式
  16. 编译工具:XMake 和 CMake对比分析
  17. android手机线控失效,耳机线控失效 苹果iOS 10.0.2终于修好了
  18. 计算机领域哪个证值钱,最值钱且相对好考的证书有哪些?
  19. python程序设计第三版约翰策勒第六章编程练习答案
  20. 眼图观测实验报告_眼图观测实验..doc

热门文章

  1. 想不到吧?数学还有如此妙用!
  2. AI浪潮席卷而来,现在加入还来得及吗?
  3. java环境怎样搭建_如何学习JAVA?怎么搭建JAVA环境?怎么安装JDK?
  4. 爱思助手短信备份到安卓_爱思助手肿么将短信导入iphone
  5. html图片宽度高度等比例绽放,css图片自动绽放大小,左右,上下居中
  6. php myadmin怎么用,关于apachemysqlphpmyadmin的安装与配置
  7. 数据库年月日时分秒_数据库基本使用系列(二)
  8. 二分法查找是基于有序_201,查找顺序查找
  9. 问题 B: 数塔问题
  10. 八数码问题I-bfs和map标记