Codeforces Round 928 (Div. 4) (A-E)

比赛地址 : 

https://codeforces.com/contest/1926

遍历每一个字符串,比较1和0的数量即可,那个大输出那个;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;using namespace std;inline void solve(){int n ; cin >> n ;for(int i=1;i<=n;i++){string s ; cin >> s ;int t = 0 ;for(char c : s){if(c=='A') t++;}if(t>=3) cout << "A" << endl;else cout << "B" << endl;}
}signed main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}

B . 

模拟,先找第一个出现的'1' , 然后求这一列1的个数(也就是正方形的一条边) : n,然后求'1'的总个数: s,判断n*n==s && 右下角那个点也是1,就能够判断是不是正方形,否则就是三角形 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;using namespace std;char a[13][13] ;inline void solve() {int n ; cin >> n ;int t = 0 ;bool tag = true;int x = 0 , y = 0 ;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){cin >> a[i][j] ;if(a[i][j]=='1' && tag){x = i ;y = j ;tag = false ;}if(a[i][j] == '1') t++;}}bool st = false ;int b = 0 ;for(int j=y;j<=n;j++){if(a[x][j]=='1') b++;// 长度		}if(x+b-1<=n&&y+b-1<=n&&a[x+b-1][y+b-1]=='1') st = true ;if(t==b*b && st) cout << "SQUARE" << endl;else cout << "TRIANGLE" << endl ;}signed main()
{IOSint _ = 1;cin >> _;while (_--) solve();return 0;
}

C

前缀和 + 预处理

可以通过前缀和进行预处理,为O(2e5+n),然后对于每一个数据,都能够通过O(1)进行输出 ;

#include<bits/stdc++.h>
using namespace std;
typedef long long LL ;
const int N = 2e5 + 10 ;
LL a[N] ;int get(int x){int t = 0 ;while(x) t+=x%10,x/=10;return t ;
}void init(){a[1] = 1 ;for(int i=2;i<=2e5;i++){a[i] = a[i-1] + get(i) ;}
}int main() {int tt ; cin >> tt ;init() ;while(tt--){int n ; cin >> n ;cout << a[n] << endl;}return 0 ;
}

数学 推式子

分情况讨论,推出数学式子 , 然后算出答案 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;using namespace std;LL get0(int n){LL ans = (n+1)*n/2 ;return ans ;
}
LL get1(int n){int x = n / 10 ;int y = n % 10 ;LL t = x * (x-1) / 2 * 10 + 45 * x + get0(y) + (y+1) * x;return t ;
}LL get2(int n){int x = n / 100 ;int y = n % 100 ;LL t = get1(y) + x * (x-1) / 2 * 100 + x * get1(99) + (y+1) * x;return t ;
}
LL get3(int n){int x = n / 1000 ;int y = n % 1000 ;LL t = get2(y) + x * (x-1) / 2 * 1000 + x * get2(999) + (y+1) * x;return t ;
}
LL get4(int n){int x = n / 10000 ;int y = n % 10000 ;LL t = get3(y) + x * (x-1) / 2 * 10000 + x * get3(9999) + (y+1) * x;return t ;
}inline void solve(){int n ; cin >> n ;if(n<10) {cout << (n+1)*n/2 << endl;return ;}if(n>=10 && n<100){int x = n / 10 ;int y = n % 10 ;LL t = x * (x-1) / 2 * 10 + 45 * x + get0(y) + (y+1) * x;cout << t << endl;return ;}if(n>=100 && n<1000){int x = n / 100 ;int y = n % 100 ;LL t = get1(y) + x * (x-1) / 2 * 100 + x * get1(99) + (y+1) * x;cout << t << endl;return ;}if(n>=1000 && n<10000){int x = n / 1000 ;int y = n % 1000 ;LL t = get2(y) + x * (x-1) / 2 * 1000 + x * get2(999) + (y+1) * x;cout << t << endl;return ;}if(n>=10000 && n<100000){int x = n / 10000 ;int y = n % 10000 ;LL t = get3(y) + x * (x-1) / 2 * 10000 + x * get3(9999) + (y+1) * x;cout << t << endl;return ;}if(n>=100000 && n<1000000){int x = n / 100000 ;int y = n % 100000 ;LL t = get4(y) + x * (x-1) / 2 * 100000 + x * get4(99999) + (y+1) * x;cout << t << endl;return ;}
}signed main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

D

哈希表 + 位运算

对于每个数来说,能与它一组的有且仅有二进制在低31位上的31位都完全相反这一个数,那么可以得到一个组最多两个数字,对于x,那么能够与它配对的数字也就是 : ((1<<31)-1) ^ x ,其中((1<<31)-1)代表2^31-1,其二进制的低31位全是一;

通过上面就可以一遍遍历,用map记录之前出现过的数,遇到能匹配的,就删掉一个 ;

int yy = (1<<31) - 1 ;
/ 一对中的所有位都不同的条件等价于当我们对 2个数进行异或时,该对产生的数的所有位都设置为 1
inline void solve2(){int n ; cin >> n ;map<int,int> mp ;int ans = 0 ;for(int i=1;i<=n;i++){int x ; cin >> x ;if(!mp[x]) ++ans,++mp[yy^x];else --mp[x] ;}cout << ans << endl ;
}

哈希表 + 字符串

如果不精通位运算,就可以直接采取hash表存字符串的方式;

这里采用set + map进行模拟 ;

LL a[N] ;string get(string s){string str = "" ;for(char c : s) str += c == '1' ? '0' : '1' ;return str;
}inline void solve(){int n ; cin >> n ;for(int i=1;i<=n;i++) cin >> a[i] ;set<string> st ;map<string,int> mp ;int x = 0 ;for(int i=1;i<=n;i++){string s = bitset<32>(a[i]).to_string();s = s.substr(1);string str = get(s) ;if(st.count(str)){x++;if(mp[str]>1){mp[str]--;}else{st.erase(str);mp[str]--;}}else{st.insert(s) ;mp[s]++;	}  }cout << n - x << endl ;
}

E

思维题

对于第一轮,就已经把全部的奇数放完了,那么之后的就全部都是偶数 ;

永远不会在非2的幂的棋步上放下棋 ,因为非2的幂的步上,一定包含一个奇数因子,会在第一轮就被放下 ;

加入上一步还剩n个棋子,那么下一步一定会下其中的一半棋子,然后模拟就好了 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;using namespace std;// 第一轮 把奇数放完了,后面一定全是偶数
// 永远不会在非2的幂的棋步上放下棋 ,因为非2的幂的步上,一定包含一个奇数因子,会在第一轮就被放下 ;void solve() {int n, k;cin >> n >> k;vector<int> v;while (n) {v.push_back((n + 1) / 2); //每次放奇数个 n /= 2;}int tot = 0, pow2 = 1;for (int x : v) {if (tot < k && k <= tot + x) {cout << pow2 * (2 * (k - tot) - 1) << '\n';return;}tot += x;pow2 *= 2;}
}signed main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}

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

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

相关文章

C++BST(二叉搜索树)应用场景

CBST可以应用于各种场景&#xff1a; 数据的快速查找&#xff1a;由于BST的特性&#xff0c;可以很方便地进行查找操作。在BST中&#xff0c;查找一个特定元素的时间复杂度为O(log n)&#xff0c;其中n是BST中节点的数量。数据的排序&#xff1a;BST可以通过中序遍历得到有序的…

Idea启动Gradle报错: Please, re-import the Gradle project and try again

Idea启动Gradle报错&#xff1a;Warning:Unable to make the module: reading, related gradle configuration was not found. Please, re-import the Gradle project and try again. 解决办法&#xff1a; 开启步骤&#xff1a;View -> Tool Windows -> Gradle 点击refe…

HN 千赞热贴|创业 4 年,那些狠狠打我脸的技术选型

Hacker News 帖子 过年这段时间&#xff0c;Hacker News 上也涌现了不少好帖子&#xff0c;除了霸榜的 Sora 外&#xff0c;技术贴最靠前的就是这篇 (Almost) Every infrastructure decision I endorse or regret after 4 years running infrastructure at a startup。作者根据…

C#面:列出 .NET 中的几种循环方法,并指出它们的不同

fo r循环&#xff1a; for 循环是一种最常见的循环方法&#xff0c;它通过指定循环的起始值、终止条件和每次迭代的步长来控制循环。 for 循环适用于已知循环次数的情况。 while循环&#xff1a; while循环是一种在循环开始之前先判断条件是否满足的循环方法。只有当条件为…

【Django开发】0到1开发美多shop项目:图形和短信验证码。全md文档笔记(附代码,已分享)

本系列文章md笔记&#xff08;已分享&#xff09;主要讨论django商城项目相关知识。项目利用Django框架开发一套前后端不分离的商城项目&#xff08;4.0版本&#xff09;含代码和文档。功能包括前后端不分离&#xff0c;方便SEO。采用Django Jinja2模板引擎 Vue.js实现前后端…

【Java多线程】线程安全问题与解决方案

目录 1、线程安全问题 1.2、线程安全原因 2、线程加锁 2.1、synchronized 关键字 2.2、完善代码 2.3、对同一个线程的加锁操作 3、内容补充 3.1、内存可见性问题 3.2、指令重排序问题 3.3、解决方法 3.4、总结 volatile 关键字 1、线程安全问题 某个代码&#xff…

初识结构体(C语言)

目录 1、结构体声明 2、结构体访问 3、结构体传参 1、结构体声明 结构是一些值的集合&#xff0c;这些值称为成员变量。结构的每一个成员可以是不同类型的变量。有点像数组&#xff0c;但是一个数组只能存放同一种类型的变量。如果要描述复杂对象的时候&#xff0c;对象由多…

基于Java SSM框架实现留学生交流互动论坛网站项目【项目源码+论文说明】

摘要 21世纪的今天&#xff0c;随着社会的不断发展与进步&#xff0c;人们对于信息科学化的认识&#xff0c;已由低层次向高层次发展&#xff0c;由原来的感性认识向理性认识提高&#xff0c;管理工作的重要性已逐渐被人们所认识&#xff0c;科学化的管理&#xff0c;使信息存…

【leetcode】常用数学题解法介绍

当涉及到ACM算法题中常见的数学常识和知识点时&#xff0c;以下是更加详细和全面的分析&#xff1a; 二进制&#xff1a; 二进制在计算机中是最基础的进制&#xff0c;它只包含两个数字0和1。在ACM算法题中&#xff0c;常用的二进制操作有&#xff1a; 位运算&#xff1a;包括…

关于三色标记算法

关于三色标记算法 三色标记算法是一种用于垃圾收集得算法&#xff0c;主要用于解决在并发垃圾收集中可能出现得对象引用更新问题。在JVM中&#xff0c;这种算法主要应用于CMS&#xff08;ConcurrentMarkSweep&#xff09;收集器和G1&#xff08;Garbage-first&#xff09;收集…

基于ant的图片上传组件封装(复制即可使用)

/*** 上传图片组件* param imgSize 图片大小限制* param data 上传数据* param disabled 是否禁用*/import React, { useState,useEffect } from react; import { Upload, Icon, message} from antd; const UploadImage ({imgSize 50,data { Directory: Image },disabled f…

Vue封装全局公共方法

有的时候,我们需要在多个组件里调用一个公共方法,这样我们就能将这个方法封装成全局的公共方法。 我们先在src下的assets里新建一个js文件夹,然后建一个common.js的文件,如下图所示: 然后在common.js里写我们的公共方法,比如这里我们写了一个testLink的方法,然后在main…

Apache Flink连载(三十):Flink 内存模型

🏡 个人主页:IT贫道-CSDN博客 🚩 私聊博主:私聊博主加WX好友,获取更多资料哦~ 🔔 博主个人B栈地址:豹哥教你学编程的个人空间-豹哥教你学编程个人主页-哔哩哔哩视频 目录

【GUI编程】Tkinter之OptionMenu

OptionMenu OptionMenu类是一个辅助类&#xff0c;它用来创建弹出菜单&#xff0c;并且有一恶搞按钮显示它。它非常类似Windows上的下拉列表插件。 如果要获取当前选项菜单的值&#xff0c;你需要把它和一个Tkinter变量联系起来。 def __init__(self, master, variable, val…

【LeetCode+JavaGuide打卡】Day19|654.最大二叉树、617.合并二叉树、700.二叉搜索树中的搜索、98.验证二叉搜索树

学习目标&#xff1a; 654.最大二叉树 617.合并二叉树 700.二叉搜索树中的搜索 98.验证二叉搜索树 学习内容&#xff1a; 654.最大二叉树 题目链接&&文章讲解 给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: 创建一个根节点&…

“无限交互,全新驾驶体验!智能语音小车,与您共同开创未来出行。”#51单片机最终项目《智能语音小车》【上】

"无限交互&#xff0c;全新驾驶体验&#xff01;智能语音小车&#xff0c;与您共同开创未来出行。”#51单片机最终项目《智能语音小车》【上】 前言预备知识1. L9110S电机控制器接线1.1 L9110S概述1.2 L9110S IO口描述1.3 L9110S 实物图1.4 L9110S与单片机接线 2. L9110前…

java基础 -- 事件监听器

要实现一个事件监听器&#xff0c;您可以使用Java中的事件模型和接口。以下是一个简单的示例&#xff0c;演示如何创建和使用一个事件监听器&#xff1a; 创建事件类&#xff08;Event Class&#xff09;&#xff1a; import java.util.EventObject;public class MyEvent ext…

ComfyUI添加IP白名单功能

AI生图很火&#xff0c;相信你对ComfyUI不陌生&#xff0c;查看ComfyUI的源码可以发现它是使用aiohttp来作为服务端的。那么我们在使用ComfyUI的时候可能需要做一些安全的限制&#xff0c;接下来我们将探讨如何在 ComfyUI 中添加 IP 白名单功能&#xff0c;以确保只有特定的用户…

PostgreSQL按日期列创建分区表

在PostgreSQL中&#xff0c;实现自动创建分区表主要依赖于表的分区功能&#xff0c;这一功能从PostgreSQL 10开始引入。分区表可以帮助管理大量数据&#xff0c;通过分布数据到不同的分区来提高查询效率和数据维护的便捷性。以下是在PostgreSQL中自动创建分区表的一般步骤&…

【Git】Gitbash使用ssh 上传本地项目到github

SSH Git上传项目到GitHub&#xff08;图文&#xff09;_git ssh上传github-CSDN博客 前提 ssh-keygen -t rsa -C “自己的github电子邮箱” 生成密钥&#xff0c;公钥保存到自己的github的ssh里 1.先创建一个仓库&#xff0c;复制ssh地址 git init git add . git commit -m …