Educational Codeforces Round 117 (Rated for Div. 2)

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}(kn1)/(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}^ni=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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/316155.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[Abp vNext 源码分析] - 3. 依赖注入与拦截器

一、简要说明ABP vNext 框架在使用依赖注入服务的时候&#xff0c;是直接使用的微软提供的 Microsoft.Extensions.DependencyInjection 包。这里与原来的 ABP 框架就不一样了&#xff0c;原来的 ABP 框架还需要抽象出来一个 IIocManager 用来管理整个 IoC 容器&#xff0c;现在…

hdu 7111-Remove

[hdu 7111] Brunhilda’s Birthday&#xff09; 题意&#xff1a; 和P6756 [BalticOI2013] Brunhilda’s Birthday&#xff09;一样的 给你p个质数集&#xff0c;您可以进行任意多次操作&#xff0c;每一次操作时&#xff0c;您选择一个素数pip_{i}pi​,这会使得n->⌊npi⌋…

Codeforces Round #757 (Div. 2)

A. Divan and a Store B. Divan and a New Project C. Divan and bitwise operations D1. Divan and Kostomuksha (easy version) D2. Divan and Kostomuksha (hard version) E. Divan and a Cottage 排序贪心 #include <iostream> #include <algorithm> #include…

dotnet core 微服务教程

这个教程主要是对于第一次使用dotnet core开发的同学。运行环境是在centos 7 &#xff0c;使用了docker容器。即这是一篇运行在linux的docker容器上的微服务的简单应用。一. 安装.NET SDK安装.NET之前&#xff0c;先安装一些依赖&#xff0c;运行下面的命令sudo rpm -Uvh https…

cf1552F. Telepanting

cf1552F. Telepanting 题意&#xff1a; 在一个坐标轴上&#xff0c;有n个传送门&#xff0c;格式为&#xff1a;xi,yi,si,可以从xi传送到yi&#xff0c;si表示状态&#xff0c;如果si为0&#xff0c;到位置xi时不会传送&#xff0c;si变为1.如果到达xi时si为1&#xff0c;则…

Educational Codeforces Round 118 (Rated for Div. 2)

A - Long Comparison B - Absent Remainder C - Poisoned Dagger D - MEX Sequences E - Crazy Robot 拿字符串比较 #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <cmath> #include <stack>…

eShopOnContainers 是一个基于微服务的.NET Core示例框架

找到一个好的示例框架很难&#xff0c;但不是不可能。大多数是小型Todo风格的应用程序&#xff0c;通常基于SimpleCRUD。值得庆幸的是&#xff0c;Microsoft已经为eShopOnContainers创建了一个基于微服务的.NET Core示例应用程序。eShopOnContainers是 .NET Core示例应用框架&a…

P1447 [NOI2010] 能量采集

P1447 [NOI2010] 能量采集 题意&#xff1a; 如果一棵植物与能量汇集机器(坐标为0&#xff0c;0)连接而成的线段上有 k 棵植物&#xff0c;则能量的损失为 2k 1 给你一个n*m的植物园&#xff0c;问能量损失是多少 1<n,m<1e5 题解&#xff1a; 本题所求式子为&#x…

P1232 [NOI2013] 树的计数

…调半天别的东西写错了&#xff0c;心力交瘁。 思路还是不会。。 具体就是二分&#xff0c;没想到&#xff0c;然后再贪心。 一直没整明白一个数它要往别的树走的条件是什么&#xff0c;日后研究。 #include <iostream> #include <cstdio> #include <cstring&…

「拥抱开源, 又见 .NET」系列第三次线下活动简报

「拥抱开源, 又见 .NET」随着 .NET Core的发布和开源&#xff0c;.NET又重新回到人们的视野。自2016年 .NET Core 1.0 发布以来&#xff0c;其强大的生命力让越来越多技术爱好者对她的未来满怀憧憬&#xff0c;越来越多的平台、框架热衷于为.NET Core不断更新的版本提供最有力的…

P3302 SDOI2013森林

P3302 [SDOI2013]森林 题意&#xff1a; 一片森林&#xff0c;有n个节点&#xff0c;m个边&#xff0c;现在有t个操作&#xff0c; Q x y k&#xff1a;Q x y k 查询点 x 到点 y 路径上所有的权值中&#xff0c;第 k 小的权值是多少 L x y 在点 x 和点 y 之间连接一条边。保证…

Codeforces Round #759 (Div. 2, based on Technocup 2022 Elimination Round 3)

感觉E思路明确只用了stl树状数组&#xff0c;F线段树复合修改&#xff0c;为什么都是2400。 A. Life of a Flower B. Array Eversion C. Minimize Distance E. Frequency Queries F. Non-equal Neighbours F : 首先 dp[i][j]sum[dp[i−1]]−dp[i−1][j]dp[i][j] sum[dp[i-1]] …

请给你的短信验证码接口加上SSL双向验证

序言去年年底闲来几天&#xff0c;有位同事专门在网上找一些注册型的app和网站&#xff0c;研究其短信接口是否安全&#xff0c;半天下来找到30来家&#xff0c;一些短信接口由于分析难度原因&#xff0c;没有继续深入&#xff0c;但差不多挖掘到20来个&#xff0c;可以肆意被调…

P2498 [SDOI2012]拯救小云公主

P2498 [SDOI2012]拯救小云公主 题意&#xff1a; 一个row * line的矩形&#xff0c;英雄在左下角(1,1),公主在右上角(row,line),有n个位置是boss。英雄现在要去公主那里&#xff0c;但是要避开boos&#xff0c;英雄决定找一条路径使到距离boss的最短距离最远。雄走的方向是任…

AtCoder Beginner Contest 230

A - AtCoder Quiz 3 B - Triple Metre C - X drawing 暂无 D - Destroyer Takahashi 暂无 贪心好难啊 E - Fraction Floor Sum F - Predilection G - GCD Permutation H - Bullion无 AAA int t;scanf("%d", &t);t t>42;printf("AGC%03d", t);BBB …

在Asp.Net Core中集成Kafka

在我们的业务中&#xff0c;我们通常需要在自己的业务子系统之间相互发送消息&#xff0c;一端去发送消息另一端去消费当前消息&#xff0c;这就涉及到使用消息队列MQ的一些内容&#xff0c;消息队列成熟的框架有多种&#xff0c;这里你可以读这篇文章来了解这些MQ的不同&#…

生成函数(母函数)

参考文章&#xff1a; 生成函数(母函数)——目前最全的讲解 《小学生都能看懂的生成函数从入门到升天教程》《生成函数全家桶》 Acwing 进阶课程–生成函数 引入 任意给定一个无限长的序列a0,a1....an....a_{0},a_{1}....a_{n}....a0​,a1​....an​.... 定义函数g(x)a0x0a1x…

AtCoder Beginner Contest 234

A - Weird Function B - Longest Segment C - Happy New Year! D - Prefix K-th Max E - Arithmetic Number F - Reordering G - Divide a Sequence 写个函数 int f(int x){return x*x2*x3;} int main() { int t;scanf("%d", &t);cout<<f(f(f(t)t)f(f(t…

分享一个.NET平台开源免费跨平台的大数据分析框架.NET for Apache Spark

今天早上六点半左右微信群里就看到张队发的关于.NET Spark大数据的链接https://devblogs.microsoft.com/dotnet/introducing-net-for-apache-spark/ &#xff0c;正印证了“微软在不断通过.NET Core补齐各领域开发&#xff0c;真正实现一种语言的跨平台”这句话。那么我们今天就…

Codeforces Round #760 (Div. 3)

E. Singers’ Tour F. Reverse G. Trader Problem 推推式子就行了。 int a[N]; int main() {int t;scanf("%d", &t);while(t --){int n;LL sum 0;scanf("%d", &n);for(int i 1;i < n;i ) scanf("%d", ai), sum a[i];a[0] a[n]…