20230103~05code
U190849 最简分式
#include<bits/stdc++.h>
using namespace std;
// gcd(a,b) = gcd(b, a%b): a,b的最大公约数 = b,a%b 的最大公约数
int gcd(int a,int b) {
// return b ? gcd(b,a%b) : a;
if(b==0) return a;
return gcd(b,a%b);
}
int main() {
int t,a,b,c,d; cin>>t;
while(t--) {
cin>>a>>b>>c>>d;
int e = a*d+b*c;
int f = b*d;
int temp = gcd(e,f);
cout<<e/temp<<" "<<f/temp<<endl;
}
return 0;
}
P5734 【深基6.例6】文字处理软件
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
// s.append(str); 在 s 后追加一个 str
// s.substr(a,b); 截取 s 的第 a 个字符后连续 b 个字符
// s.insert(a, str); 在 s 的第 a 个字符后插入字符串 str
// s.find(str) 查询 str 第一次出现的下标,如果没有出现则返回 -1
int main(){
string s,str; int t,op,a,b; cin>>t>>s;
while(t--){
cin>>op;
if(op==1){
cin>>str; s.append(str);
cout<<s<<endl;
}else if(op==2){
cin>>a>>b; s=s.substr(a,b);
cout<<s<<endl;
}else if(op==3){
cin>>a>>str; s.insert(a, str);
cout<<s<<endl;
}else if(op==4){
cin>>str;
cout<<(int)s.find(str)<<endl;
}
}
return 0;
}
P1104 生日
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=110,INF=0x3f3f3f3f;
int n;
struct T {
string name;
int y,m,d,id;
}t[N];
bool cmp(T a, T b){
if(a.y!=b.y) return a.y < b.y;
if(a.m!=b.m) return a.m < b.m;
if(a.d!=b.d) return a.d < b.d;
return a.id > b.id;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
cin>>t[i].name>>t[i].y>>t[i].m>>t[i].d;
t[i].id = i;
}
sort(t+1, t+n+1, cmp);// sort(首地址,末地址后一位,比较方式);
for(int i=1; i<=n; i++){
cout<<t[i].name<<endl;
}
return 0;
}
P4305 [JLOI2011]不重复数字
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
int main() {
int t,x,n; cin>>t;
while(t--) {
set<int> s; cin>>n;
while(n--) {
cin>>x;
if(s.count(x)==0) cout<<x<<" ";
s.insert(x);
}
cout<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
int main() {
int t,x,n; scanf("%d", &t);
while(t--) {
map<int,int> mp; scanf("%d", &n);
while(n--) {
scanf("%d", &x);
if(mp.count(x)==0) printf("%d ", x);
mp[x] = 1; // x ---> 1
}
printf("\n");
}
return 0;
}
P8218 【深进1.例1】求区间和
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+10, INF=0x3f3f3f3f;
int n,q,l,r,a[N],s[N];
int main() {
// 笔记:前缀和 s[i] = a[1]+a[2] +... +a[i]
// s[i] = s[i-1] + a[i]
// 区间和 [l,r] = s[r] - s[l-1]
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<=n; i++) s[i]=s[i-1]+a[i];
cin>>q;
while(q--) {
cin>>l>>r;
cout<<s[r] - s[l-1]<<endl;
}
return 0;
}
P3397 地毯
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e3+10,INF=0x3f3f3f3f;
int n,m,v[N][N];
int main(){
int x1,x2,y1,y2;
cin>>n>>m;
for(int i=1; i<=m; i++){
cin>>x1>>y1>>x2>>y2;
for(int x=x1; x<=x2; x++){
for(int y=y1; y<=y2; y++){
v[x][y] ++;
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cout<<v[i][j]<<" ";
} cout<<endl;
}
return 0;
}
P2367 语文成绩
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e6+10,INF=0x3f3f3f3f;
int n,p,a[N],b[N];
int main(){
cin>>n>>p; int l,r,d;
for(int i=1; i<=n; i++) cin>>a[i];
while(p--){
cin>>l>>r>>d;
b[l] += d;
b[r+1] -= d;
}
int tmin=2e9;
for(int i=1; i<=n; i++){
b[i] += b[i-1];
if(a[i]+b[i] < tmin) tmin=a[i]+b[i];
}
cout<<tmin;
return 0;
}
CF276C Little Girl and Maximum Sum
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10,INF=0x3f3f3f3f;
int n,q,a[N],b[N], l,r;
int main(){
cin>>n>>q;
for(int i=1; i<=n; i++) cin>>a[i];
while(q--){
cin>>l>>r;
b[l] ++;
b[r+1] --;
}
for(int i=1; i<=n; i++) b[i]+=b[i-1];
sort(a+1, a+1+n);
sort(b+1, b+1+n);
LL s=0; // 2e5 * 2e5
for(int i=1; i<=n; i++) s += 1ll*a[i]*b[i];
cout<<s;
return 0;
}
P1451 求细胞数量
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=110,INF=0x3f3f3f3f;
char s[N][N];
int n,m,ans=0;
bool check(int x,int y) {
return x>=0 && x<n &&y>=0 && y<m &&s[x][y]!='0';
}
void dfs(int x,int y) {
s[x][y]='0';
if(check(x+1,y)) dfs(x+1, y);
if(check(x-1,y)) dfs(x-1, y);
if(check(x,y-1)) dfs(x, y-1);
if(check(x,y+1)) dfs(x, y+1);
}
int main() {
cin>>n>>m;
for(int i=0; i<n; i++) cin>>s[i];
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(s[i][j]!='0') {
ans++, dfs(i,j);
}
}
}
cout<<ans;
return 0;
}
P1706 全排列问题
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
int n,vis[N],ans[N];
// 坐第 m 个板凳
void dfs(int m) {
if(m > n) {
for(int i=1; i<=n; i++)
cout<<setw(5)<<ans[i];
cout<<endl; return;
}
for(int i=1; i<=n; i++) { // 第 i 个人
if(vis[i]==0) {
vis[i]=1, ans[m]=i; // 第 m 个板凳坐的是 i.
dfs(m+1);
vis[i]=0; // 回溯
}
}
}
int main() {
cin>>n; dfs(1);
return 0;
}
20230103~05code的更多相关文章
- 【动图解释】关系数据库de关系代数小记
本文章在 Github 撰写,同时在 我的博客 进行了发布. 最近学数据库概论学到了关系数据库的关系代数了.哎嘛,真的把我整晕了,尤其是关系代数的使用,很容易让人被蒙在鼓里. 对我来说槽点最大的莫过于 ...
- Nacos详解
Nacos是什么 欢迎来到Nocos的世界! 组成部分 全称 描述 Na naming/nameServer 即服务注册中心,与 Spring Cloud Eureka 的功能类似. co confi ...
- 避免用Apache Beanutils进行属性的copy。why?让我们一起一探究竟
在实际的项目开发中,对象间赋值普遍存在,随着双十一.秒杀等电商过程愈加复杂,数据量也在不断攀升,效率问题,浮出水面. 问:如果是你来写对象间赋值的代码,你会怎么做? 答:想都不用想,直接代码走起来,g ...
- 【项目实战】从零到一搭建Spring Boot整合Mybatis-plus
前言 2023年想搭建一套属于自己的框架,做一个属于自己想法的项目.这些年工作中一直用公司已有的框架,以前有跟着学习视频搭建过,但自己真正动手搭建时发现问题还是很多,比如没有引入Mybatis-plu ...
随机推荐
- DTMF2num拨号音识别
说明 很多出题人可能会把手机或者其他设备打电话的拨号音作为一个题目技能中的考察点. 什么是DTMF? 双音多频的拨号键盘是4×4的矩阵,每一行代表一个低频,每一列代表一个高频.每按一个键就发送一个高频 ...
- C/C++语言 MD5例子
之前研究了一下在C中进行MD5加密,由于找了很久没有找到现成的库文件,所以所幸自己去写了一下.个人感觉C的便捷性没有Python好的原因就是这里. 下面是我写的一个例子. mian.cpp: 点击查看 ...
- [python] Python二维码生成器qrcode库入门
Python二维码生成器qrcode库入门 qrcode是二维码生成的Python开源库,官方地址为python-qrcode.所有代码见:Python-Study-Notes. 文章目录 Pytho ...
- [cocos2d-x]捕鱼达人鱼和子弹的碰撞检测
检测方法如图所示,步骤在注释中也写的很清楚了.
- MySQL性能优化浅析及线上案例
作者:京东健康 孟飞 1. 数据库性能优化的意义 业务发展初期,数据库中量一般都不高,也不太容易出一些性能问题或者出的问题也不大,但是当数据库的量级达到一定规模之后,如果缺失有效的预警.监控.处理等手 ...
- CF1237H Balanced Reversals
H - Balanced Reversals 首先可以将相邻的两个点分到一个组中 特判无解的情况:00的数量不相等或11的数量不相等 若10的数量相等(此时01的数量也相等,因为知道10的数量后01的 ...
- activemq插件在eos中的开发
ActiceMQ-CPP消息插件是CMS的一种实现,是一个能够与ActiveMQ进行通信的C++客户端库,ActiveMQ-CPP的架构设计能够支持可插拨的传输协议和消息封装格式,并且支持客户端容量, ...
- 我为什么要放弃RESTful,选择拥抱GraphQL
背景 REST作为一种现代网络应用非常流行的软件架构风格,自从Roy Fielding博士在2000年他的博士论文中提出来到现在已经有了20年的历史.它的简单易用性,可扩展性,伸缩性受到广大Web开发 ...
- Docker不做虚拟化内核,对.NET有什么影响?
引子 前两天刷抖音,看见了这样一个问题. 问题:容器化不做虚拟内核,会有什么弊端?Java很多方法会跟CPU的核数有关,这个时候调用系统函数,读到的是宿主机信息,而不是我们限制资源的大小. 思考:在我 ...
- 洛谷P1365 期望dp
题目描述 一个o/x序列的得分为其中每个o的极大连续子段长度的平方和,比如ooxxxxooooxxx,分数就是 \(2 \times 2 + 4 \times 4 = 4 +16=20.\) 现给定一 ...