当前位置: 首页 > news >正文

天津大学2024-2025 预推免 第一批机试题目纯暴力题解

题目A:流量计费

#include <bits/stdc++.h>
using namespace std;int main(){int t;cin>>t;while(t--){int m;cin>>m;int num=0;int temp;for(int i=1;i<=m;i++){cin>>temp;num+=temp;}if(t==1){if(num<=500)cout<<10;else{cout<<10+(num-500);} }else{if(num<=500)cout<<10<<endl;else{cout<<10+(num-500)<<endl;} }}
}

题目B:买水果

#include <bits/stdc++.h>
using namespace std;/*
8 7 1
8 6 1
a从小到大{o从大到小
}
o从大到小{a从大到小
}
*/
int main(){int t;cin>>t;while(t--){int n,m;int ans=0;cin>>n>>m;vector<int> a(n+5,0);vector<int> o(m+5,0);for(int i=0;i<n;i++)cin>>a[i];for(int i=0;i<m;i++)cin>>o[i];sort(a.begin(),a.end(),greater<int>());sort(o.begin(),o.end(),greater<int>());for(int i=0;i<n;i++){for(int j=ans;j<m;j++){if(a[j]>o[i]){ans++;break;}}}if(!t) cout<<ans;else cout<<ans<<endl;}return 0;
}

题目C:星期几?

#include <bits/stdc++.h>
using namespace std;int rl[15]={0,31,28,31,30,31,30,31,31,30,31,30,31};
map<int,string> week={{1,"Monday"},{2,"Tuesday"},{3,"Wednesday"},{4,"Thursday"},{5,"Friday"},{6,"Saturday"},{0,"Sunday"}
};bool run(int y){if(y%400==0||(y%4==0&&y%100!=0)) return true;return false;
}
int to_days(string s){int days=0;string ty=s.substr(0,4);int y=stoi(ty);string tm=s.substr(5,2);int m=stoi(tm);string td=s.substr(8,2);int d=stoi(td);for(int i=1900;i<y;i++){if(run(i)) days+=366;else days+=365;}for(int j=1;j<m;j++){days+=rl[j];if(run(y)&&j==2) days+=1;}days+=d;return days;
}int main(){int t;cin>>t;while(t--){string s;cin>>s;int pre_ans=to_days(s)%7;if(t) cout<<week[pre_ans]<<endl;else cout<<week[pre_ans];}return 0;
}

题目D:完美子序列

#include <bits/stdc++.h>
using namespace std;/*
2
9 10
19 18 16 18 6 6 11 13 14
5 8
17 19 13 18 14暴力:让每个位置都充当一次起点,向后尝试增加长度
每个位置{逐一增加长度
}
*/int main(){int t;cin>>t;while(t--){int n,m;cin>>n>>m;vector<int> a(n+5,0);for(int i=0;i<n;i++) cin>>a[i];int ans=0;for(int i=0;i<n;i++){int cha=0,end=i;int maxx=a[i],minn=a[i];while(cha<=m){   //新end加进来未知是否符合要求cha=max(cha,abs(maxx-minn));  if(cha<=m){end+=1;maxx=max(maxx,a[end]);minn=min(minn,a[end]);}}ans=max(ans,end-i+1-1); //+1长度;-1最后end一定多1}if(!t) cout<<ans;else cout<<ans<<endl;}return 0;
}

题目E:最长子串

#include <bits/stdc++.h>
using namespace std;/*
2
abbccdde
abcedfg*/bool check(string s){map<char,int> mp;int len=s.length();for(int i=0;i<len;i++){mp[s[i]]+=1;if(mp[s[i]]>2) return false;}for(auto v:mp){if(v.second!=2) return false;}return true;
}int main(){int t;cin>>t;while(t--){string s;cin>>s;int len=s.length();int ans=0;for(int l=0;l<len;l++){for(int r=l+1;r<len&&r<l+52;r+=2){string now=s.substr(l,r-l+1);if(check(now)) ans=max(ans,r-l+1);}}if(t) cout<<ans<<endl;else cout<<ans;}return 0;
}

文章转载自:

http://kZWNQ8w8.wgkqq.cn
http://VJ3JpE9S.wgkqq.cn
http://ME4Vnlm9.wgkqq.cn
http://GeznkJrg.wgkqq.cn
http://eag9LiKu.wgkqq.cn
http://ELQP4ZpC.wgkqq.cn
http://PDgL8GDi.wgkqq.cn
http://XtCWH9AF.wgkqq.cn
http://cx4BcfB8.wgkqq.cn
http://7fLHcFVQ.wgkqq.cn
http://LDNEmZ82.wgkqq.cn
http://SwzGZvkX.wgkqq.cn
http://vMoPwGNi.wgkqq.cn
http://opMrb0Ta.wgkqq.cn
http://kUo1gg8M.wgkqq.cn
http://cGWZUwb4.wgkqq.cn
http://gOxhRVWI.wgkqq.cn
http://THfTkX1x.wgkqq.cn
http://H9jHY8OH.wgkqq.cn
http://IfoVvz9I.wgkqq.cn
http://R1DRo82U.wgkqq.cn
http://FSKPWXgS.wgkqq.cn
http://zDCwNWAK.wgkqq.cn
http://0BbF3JS3.wgkqq.cn
http://o2gkeWZt.wgkqq.cn
http://54iTOnwq.wgkqq.cn
http://UPsXH3Ud.wgkqq.cn
http://s6SS5p8A.wgkqq.cn
http://DdspaoOC.wgkqq.cn
http://KRtIcnNo.wgkqq.cn
http://www.dtcms.com/a/370625.html

相关文章:

  • 金属也有“记忆力”?—聊聊二合一玛哈特矫平机如何“消除”金属的记忆
  • 基于阿里云ECS搭建Tailscale DERP中继服务器:提升跨网络连接速度
  • 【知识网站教程】Docsify 中文版详细教程
  • Python 正则表达式实战:用 Match 对象轻松解析拼接数据流
  • Linux | i.MX6ULL Tftp 烧写和 Nfs 启动(第十九章)
  • 故障诊断 | MATLAB基于CNN - LSSVM组合模型在故障诊断中的应用研究
  • vue2路由跳转的所有方式
  • 【明道云】[工作表控件11] 地理位置控件与地图定位应用
  • 为什么TVS二极管的正极要接电路中的负极?-ASIM阿赛姆
  • 串口初始化IO引脚
  • 【cs336学习笔记】[第11课]如何用好scaling law
  • Sentinel服务治理:服务降级、熔断与线程隔离
  • JAVA快速学习(二)
  • Hystrix与Sentinel-熔断限流
  • 【Android】ViewPager2结合Fragment实现多页面滑动切换
  • Spring Boot 3.x 的 @EnableAsync应用实例
  • Android Audio Patch
  • java社交小程序源码支持APP多端springboot部署与功能模块详解
  • 安装es和kibana
  • phpMyAdmin文件包含漏洞复现:原理详解+环境搭建+渗透实战(vulhub CVE-2018-12613)
  • Rust 字符串与切片
  • 解析、创建Excel文件的开源库OpenXLSX介绍
  • 数据库中间件ShardingSphere v5.2.1
  • 大模型推理时的加速思路?
  • (数据结构)哈希碰撞:线性探测法 vs 拉链法
  • 如何进行神经网络的模型训练(视频代码中的知识点记录)
  • Linux--命名管道
  • 【继承和派生】
  • IDEA修改系统缓存路径,防止C盘爆满
  • scikit-learn零基础配置(含python、anaconda)