Codeforces Round 867 (Div. 3)(A题到E题)

2023-11-15

链接:Dashboard - Codeforces Round 867 (Div. 3) - Codeforces

头一次div3做出来四题,第五题也差临门一脚,赛后看到别人e题跟自己几乎一样的思路肠悔青了,还得练才行

A. TubeTube Feed

签到题,找时间+当前页面耗时最大暴力水过~

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod=1000000007;
typedef pair<int,int>PII;

int a[105],b[105];
signed main(void){
	ios;
	int q;
	cin>>q;
	while(q--){
		int n,t,cnt=-1,mi=0,xb=-1;
		cin>>n>>t;
		for(int i=1;i<=n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			cnt++;
		cin>>b[i];
		if(cnt+a[i]<=t){
				if(max(b[i],mi)==b[i]){
					mi=b[i];
					xb=i;
				}
			}
		}
		if(xb==-1)cout<<-1<<endl;
		else cout<<xb<<endl;
	}
	return 0;
}

B. Karina and Array

简单思维题,只需先排序然后比较前俩个元素之和与后俩个元素之和就可以得出答案

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int a[2000005];
signed main(void){
	ios;
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		sort(a+1,a+1+n);
		int ans1=a[n]*a[n-1];
		int ans2=a[1]*a[2];
		cout<<max(ans1,ans2)<<endl;
	}
	return 0;
}

C. Bun Lover

找规律的题,巧克力黄条从中间垂直竖条开始对称长度和是1 2 4 6以此类推,但时间设了个坑,要用高中学的Sn公式而不是循环+2,循环+2亲试tle3

// Problem: C. Bun Lover
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/C
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main(void){
	ios;
	int tt;
	cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		int ans=4*4+10,t=n-3;
		
		int temp1=(t-1)*3;
		int temp2=(t-1)*(t+2)/2;
		ans+=2*temp1+2*temp2;
		//cout<<ans<<endl<<4*n<<endl;
	cout<<ans+n-4<<endl;
	}
	return 0;
}

D. Super-Permutation

听群友说这个好像是oiwiki上的原题,没写过。打表找的规律,附上打表代码

打表代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int N=3e5+5;
int n;
int h[10],st[10];
int flat=0;
void dfs(int x)
{
    if(x==n+1){
        vector<int> s(n+1);
        set<int> z;
        for(int i=1;i<=n;i++){
            s[i]=s[i-1]+h[i];
            z.insert(s[i]%n+1);
        }
        int cnt=1;
        if(z.size()==n){
            for(auto x: z){
                if(x==cnt){
                    cnt++;
                    continue;
                }
            }
            if(cnt==n+1){
                flat=1;
                for(int i=1;i<=n;i++){
                    cout<<h[i]<<" ";
                }
                cout<<endl;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(!st[i]){
            st[i]=1;
            h[x]=i;
            dfs(x+1);
            st[i]=0;
        }
    }
}

void solve()
{
    cin>>n;
    dfs(1);
    if(!flat){
        cout<<-1<<endl;
    }
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    system("pause");
    return 0;
}

ac代码:

// Problem: D. Super-Permutation
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main(void){
	ios;
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		if(n%2==1){
			if(n==1)cout<<1<<endl;
			else cout<<-1<<endl;
		}
		else{
			//cout<<n<<" ";
			int x=n;
			for(int i=1;i<=n/2;i++){
				cout<<x<<" "<<i*2-1<<" ";
				x-=2;
			}
			cout<<endl;
		}
	}
	return 0;
}

E. Making Anti-Palindromes

本场最遗憾的题,这题出了估计rating得加接近100,先贴出赛时没过的代码

// Problem: E. 制作反回文
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

char a[200005];
signed main(void){
	ios;
	int t;
	cin>>t;
	while(t--){
		int n;
		map<char,int>b;
		map<char,int>c;
		cin>>n;
		int f=1;
		int m=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			c[a[i]]++;
			m=max(m,c[a[i]]);
			if(i!=1&&a[i]!=a[i-1])f=0;
		}
		if(n%2==1||f||m>n/2){
			cout<<-1<<endl;
			continue;
		}
		int ma=0;
		for(int i=1;i<=n/2;i++){
			if(a[i]==a[n-i+1])b[a[i]]++;
			if(b[a[i]]==max(b[a[i]],ma)){
				ma=max(b[a[i]],ma);
				//temp=b[a[i]]
			}
		}
		int sum=0;
		for(auto i:b){
			sum+=i.second;
		}
		//cout<<sum<<" "<<ma<<" ";
		if(ma*2>sum)cout<<ma<<endl;
		else{
			cout<<sum-ma<<endl;
		}
		/*if(ma>=n/2-ma)cout<<ma<<endl;
		else*/ 
	}
	return 0;
}

这题思路是:首先长度如果为奇数或者单个字母数量出现次数超过总长度的一半就肯定不成立,

然后形成回文的字符其实只要一边互相交换就可以不形成回文了,具体操作如下

  统计每个形成回文字符的各个字符类型的数量sum和最多出现的那个形成回文的字符的数量max,我的代码里的sum和ma是只统计了一边的数量所以后面比较*了2,然后比较是max与sum的二分之一比较,如果大于就直接输出ma,否则输出(sum+1)/2,+1是因为如果sum是奇数的话,/2会漏掉中间那个字符。

比赛时就是那个输出的else想歪了,以为只用换sum-ma次就能完成所有调换,赛后画图+结合别人思路发现并不是这么回事

ac代码:

// Problem: E. 制作反回文
// Contest: Codeforces - Codeforces Round 867 (Div. 3)
// URL: https://codeforces.com/contest/1822/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<set>
#include<unordered_map>
#include<numeric>//partial_sum

using namespace std;

#define int long long
#define endl "\n" 
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

char a[200005];
signed main(void){
	ios;
	int t;
	cin>>t;
	while(t--){
		int n;
		map<char,int>b;
		map<char,int>c;
		cin>>n;
		int f=1;
		int m=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			c[a[i]]++;
			m=max(m,c[a[i]]);
			if(i!=1&&a[i]!=a[i-1])f=0;
		}
		if(n%2==1||f||m>n/2){
			cout<<-1<<endl;
			continue;
		}
		int ma=0;
		for(int i=1;i<=n/2;i++){
			if(a[i]==a[n-i+1])b[a[i]]++;
			if(b[a[i]]==max(b[a[i]],ma)){
				ma=max(b[a[i]],ma);
				//temp=b[a[i]]
			}
		}
		int sum=0;
		for(auto i:b){
			sum+=i.second;
		}
		//cout<<sum<<" "<<ma<<" ";
		if(ma*2>sum)cout<<ma<<endl;
		else{
			cout<<(sum+1)/2<<endl;
		}
		/*if(ma>=n/2-ma)cout<<ma<<endl;
		else*/ 
	}
	return 0;
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeforces Round 867 (Div. 3)(A题到E题) 的相关文章

随机推荐

  • 网络编程基础

    目录 一 网络的概念 1 认识网络 2 网络的发展 二 协议 1 网络问题的产生 2 什么是协议 3 网络协议 三 协议分层 1 协议分层的概念 2 OSI七层模型 3 TCP IP四层 五层 模型 1 物理层 2 数据链路层 网卡层 3
  • 宝塔面板获取默认账号密码

    bt default
  • 安装ssl证书后报错Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.

    刚刚安装完ssl证书后 报错 org apache catalina LifecycleException Protocol handler start failed at org apache catalina connector Con
  • 物联网毕设 -- 智能热水器(GPRS+APP+OneNET)

    目录 前言 一 连线图 1 原理图 2 PCB效果 3 实物效果 4 功能概括 1 硬件端 2 APP端 3 云平台端 演示视频 二 底层代码使用方式 1 使用说明 2 下载程序 3 查看云平台 三 APP使用方式 1 下载APP 1 操作
  • 【XGBoost】第 5 章:XGBoost 揭幕

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • 增益带宽积 压摆率

    带宽 它指的是电路可以保持稳定工作的频率范围 选高速运放能减少对贷款的影响 只要能够完美再现方波 就是高带宽电路 带宽与压摆率同时变化 高频下 增益就缩小了 说明增益是有带宽的 在一定频率内增益才稳定 一倍放大 与 10倍放大输出用1 10
  • AntDesign-vue-Tree组件-拖动排序

  • c++primer plus第一章复习题和编程练习答案

    复习题 c 程序的模块是 函数 include
  • MATLAB —— 低通滤波器设计与信号滤波

    百度百科 简介 低通滤波器是容许低于截止频率的信号通过 但高于截止频率的信号不能通过的电子滤波装置 1 提取滤波器 系数矩阵 打开工具 MATLAB APP Filter Designer 参数设置 滤波器类型 Response Type
  • 爬虫实例——某翻译网站参数sign的构造

    1 网页分析 该翻译网站为进行Ajax加载的网站 针对这种网页的爬取 一般有两种方式 使用Selenium等模拟浏览器的方式进行爬取 这种方式实现起来较为简单 但是爬取速度相对较慢 直接对网站的接口进行请求 爬取速度相对较快 但是某些网站的
  • 7 125 kHz RFID技术

    ATA5577C应答器芯片 芯片性能和电路组成 主要技术性能 低功耗 低工作电压 非接触能量供给和读 写数据 工作频率范围为100 150 kHz EEPROM存储器容量为363位 分为11块 每块33位 具有7块用户数据 每块32位 共2
  • 算法分析02--分治法

    3 分治法 3 1递归 递归是指子程序 或函数 直接调用自己或通过一系列调用语句间接调用自己 是一种描述问题和解决问题的常用方法 使用递归技术往往使函数的定义和算法的描述简洁且易千理解 递归有两个基本要素 边界条件 即确定递归到何时终止 也
  • FASTAI and Fine-Tuning BERT with FastAI

    这是一篇笔记类型文章 主要是从新学习一下fastai 和实践 pytorch pretrained BERT 和 pytorch transformers 对接fastai 后简洁快速实现bert模型的训练和执行任务 我还是一个小白 大佬看
  • python Elasticsearch 排序

    sort 与query是同级的 Elasticsearch python sort sort score order desc query function score query match all script score lang p
  • 接口报错之number值过大问题

    number的最大的值为2的53次方 9007199254740992 16位 当你传入的参数为Number类型时候超过16位 js就识别不了 接口会出现错误的情况 可以直接改成字符串就好了 1 JavaScript中所有的数字 无论是整数
  • 合工大 编译原理 实验二 LL1 自动生成M[A,a]

    实验目的 通过完成预测分析法的语法分析程序 了解预测分析法和递归子程序法的区 别和联系 使学生了解语法分析的功能 掌握语法分析程序设计的原理和构造方 法 训练学生掌握开发应用程序的基本方法 有利于提高学生的专业素质 为培 养适应社会多方面需
  • C++ *和&

    简单理解 是指向内存的地址变量 是取变量的地址 介绍参见 https www cnblogs com mr stn p 9037773 html简介
  • spring boot项目显示3行日志错误,内置tomcat不可使用

    spring boot项目显示3行日志错误 内置tomcat不可使用 首先这中错误是只显示三行 第一种方法是没有用spring boot starter web 在pom中将这个依赖放在第一个 第二种方法是继承ServletInitiali
  • 详解如何将python3.6软件的py文件打包成exe程序

    本文来源于公众号 csdn2299 喜欢可以关注公众号 程序员学府 这篇文章主要介绍了详解如何将python3 6软件的py文件打包成exe程序 小编觉得挺不错的 现在分享给大家 也给大家做个参考 一起跟随小编过来看看吧 在我们完成一个Py
  • Codeforces Round 867 (Div. 3)(A题到E题)

    链接 Dashboard Codeforces Round 867 Div 3 Codeforces 头一次div3做出来四题 第五题也差临门一脚 赛后看到别人e题跟自己几乎一样的思路肠悔青了 还得练才行 A TubeTube Feed 签