Codeforces Round #730 (Div. 2) +403

题目链接

https://codeforces.com/contest/1543

A 题意

给出a,b可以同时对他们加一或减一,不能为负,求gcd最大情况,以及此时操作步数。注意GCD(x,0)为x,若可无限大输出0 0

A 思路

操作后设为a+k,b+k. gcd(a+k,b+k)=gcd(b+k,a-b)若a==b,答案为b+k,可到无穷大,输出0 0,否则答案为a-b,那么只需要找到b+k为a-b整数倍即可。会有两个最接近的答案,算出来取min

A 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=200505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int ans;
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
        cin>>tn;
        while(tn--){
            cin>>n>>m;
            if(n<m)swap(n,m);
            if(n==m){
                cout<<"0 0"<<endl;
            }
            else{
                cout<<n-m<<' ';
                int ma=inf;
                int a=m/(n-m),b=(m-1)/(n-m)+1;
                ma=min(abs(m-a*(n-m)),abs(b*(n-m)-m));
               // for(int i=0;;i++){
               //     int d=i*(n-m)-m;
               //     d=abs(d);
               //     if(d<ma)    ma=d;
               //     else break;
               // }
                cout<<ma<<endl;
            }
        }
	} 
						
B 题意

给出数组,可以任意重新赋值,满足总和不变即可,计算 ∑ i = 1 n ∑ j = i + 1 n ∣ a i − a j ∣ \sum _{i=1}^n\sum _{j=i+1}^n|ai−aj| i=1nj=i+1naiaj

B 思路

贪心。扰动法可知各个数字确定后排序不会影响答案。因此尽量平均分,最后可以分成a个i和b个i+1的形式答案为a*b

B 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=200505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int a[maxn];
    int ans;
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
        cin>>tn;
        while(tn--){
            cin>>n;
            int s=0;
            for(int i=1;i<=n;i++){
                int t;
                cin>>t;
                s+=t;
            }
            if(s%n==0){
                cout<<0<<endl;
                continue;
            }
            else{
                int d=s-(s/n)*n;
                cout<<d*(n-d)<<endl;
            }
        }
	} 
						
C 题意

摸奖,三个奖概率为p1,p2,p3,给出系数v,若摸到第三号奖游戏结束,否则:

  • 如果摸到的奖的概率大于v,则他的概率-=v,另外两个奖概率+=v/2。
  • 如果摸到的奖的概率小于等于v,则他的概率归0,另外两个奖均分地加上他的概率,这个奖概率置为0后就再也不会增加概率了

求结束步数期望。

C 思路

像期望dp那样思考转移方程,dp[i][j][k]=i * dp[i-v][j+v/2][k+v/2]+j * dp[i+v/2][j-v][k+v/2]+1。(置为0的情况无非就是个加个if,这里简化。)因为ijk是浮点数,考虑转成记忆化搜索,用map存放答案即可。但是看题解说v>0.1,状态较少可以直接暴搜。。总之就是个期望dp思想的搜索。

注意浮点数精度问题,这次也是整理了个浮点数精度板子

C 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=200505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int ans;
    double a,b,c,d;
    double eps=1e-8;
    map<pair<pair<double,double>,double>,double>mp;
    inline  int  sgn( double  x) {//和0比,大于返1等于返0小于返-1
        return  (x > eps) - (x < -eps);
    }
    //x = 0 写成 sgn(x) == 0
    //x < 0 写成 sgn(x) < 0
    //x > 0 写成 sgn(x) > 0
    //x > y 写成 sgn(x - y) > 0
    //x == y 写成 sgn(x - y) == 0
    //x >= y 写成 sgn(x - y) >= 0
    double dfs(double i,double j,double k){
        if(mp[{{i,j},k}])
            return mp[{{i,j},k}];
        if(!sgn(k-1)) 
            return 1;
        double rec=0;
        if(i){
            if(j){
                if(sgn(i-d)>0)   rec+=i*dfs(i-d,j+d/2,k+d/2);
                else    rec+=i*dfs(0,j+i/2,k+i/2);
            }
            else{
                if(sgn(i-d)>0)   rec+=i*dfs(i-d,0,k+d);
                else    rec+=i;
            }
        }
        if(j){
            if(i){
                if(sgn(j-d)>0)   rec+=j*dfs(i+d/2,j-d,k+d/2);
                else    rec+=j*dfs(i+j/2,0,k+j/2);
            }
            else{
                if(sgn(j-d)>0)   rec+=j*dfs(0,j-d,k+d);
                else    rec+=j;
            }
        }

        

        rec+=1;
        return mp[{{i,j},k}]=rec;
    }
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
        cin>>tn;
        while(tn--){
            mp.clear();
            mp[{{0,0},1}]=1;
            cin>>a>>b>>c>>d;
            cout<<fixed<<setprecision(12)<<dfs(a,b,c)<<endl;
        }
	} 
						
D1 题意

此题为2进制异或。

初始密码x,属于0到n-1。你有n次机会猜。假如你猜了y,那么密码会变成z使得x^z=y。交互题让你猜密码

D1 思路

0到n-1,n次机会,我们直接枚举每个密码进行询问。但有个问题,我们需要抵消之前询问的影响。
根据二进制异或,易知z=x^y,那假如下一次我们猜k,答案还是错的,新密码z‘ =k ^ z,我们希望通过猜k而不是猜y+1来抵消之前的影响,也就是希望找到k使得z‘ = k^z = k^ x ^ y=x^ (y+1) 。解得z=(y+1)^y 。所以我们每次猜测密码为x时,输出询问x ^ (x-1)即可。

D1 代码
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib> 
#include<chrono>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=200505;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int ans;
	signed main(){
        IOS
		#ifndef ONLINE_JUDGE
		    freopen("IO\\in.txt","r",stdin);
		    freopen("IO\\out.txt","w",stdout);
        #endif
		int tn=1;
        cin>>tn;
        while(tn--){
            cin>>n>>m;
            int last=0;
            for(int i=0;i<n;i++){
                cout<<(i^last)<<endl;
                cout.flush();
                cin>>k;
                if(k==1)    break;
                else if(k==-1)  exit(0);
                else{
                    last=i;
                }
            }
        }
	} 
						
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【优质项目推荐】 1、项目代码均经过严格本地测试,运行OK,确保功能稳定后才上传平台。可放心下载并立即投入使用,若遇到任何使用问题,随时欢迎私信反馈与沟通,博主会第一时间回复。 2、项目适用于计算机相关专业(如计科、信息安全、数据科学、人工智能、通信、物联网、自动化、电子信息等)的在校学生、专业教师,或企业员工,小白入门等都适用。 3、该项目不仅具有很高的学习借鉴价值,对于初学者来说,也是入门进阶的绝佳选择;当然也可以直接用于 毕设、课设、期末大作业或项目初期立项演示等。 3、开放创新:如果您有一定基础,且热爱探索钻研,可以在此代码基础上二次开发,进行修改、扩展,创造出属于自己的独特应用。 欢迎下载使用优质资源!欢迎借鉴使用,并欢迎学习交流,共同探索编程的无穷魅力! 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip 基于业务逻辑生成特征变量python实现源码+数据集+超详细注释.zip
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值