当前位置:网站首页>20排位赛3
20排位赛3
2022-07-07 07:09:00 【moyangxian】
A
题意:略
题记:略
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int a[N];
int main(){
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<max(0,a[2]-a[1]-a[0]+1)<<endl;
return 0;
}
B
题意:略
题记:找字符串的最长公共前后缀,用substr()函数或者求next函数。
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int nxt[N];
char s[N];
int n,k;
void getnext(){
int i=0,j=-1;
nxt[0]=-1;
while(i<n){
if(j==-1||s[i]==s[j])
i++,j++,nxt[i]=j;
else
j=nxt[j];
}
}
int main(){
cin>>n>>k;
cin>>s;
getnext();
cout<<s;
for(int i=1;i<=k-1;i++)
cout<<(s+nxt[n]);
return 0;
}
C
题意:略
题记:总共可以看到n/x个灯笼,r/x表示1~ r能看到多少灯笼,(l-1)/x表示1 ~ (l-1)能看到多少灯笼。(n/x)-r/x+(l-1)/x即答案。
#include<bits/stdc++.h>
using namespace std;
const int N=110;
void solve(){
int n,x,l,r;
cin>>n>>x>>l>>r;
cout<<(n/x)-r/x+(l-1)/x<<endl;
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
return 0;
}
D
题意:略
题记:每次sum都能减去一个(a-b),所以将(a-b)作为关键字降序排序,每次将sum减一下即可。最后再判断一下sum是否大于m。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
struct Node{
int a,b;
bool operator<(const Node &W)const{
return a-b>W.a-W.b;
}
}t[N];
void solve(){
int n,m;
cin>>n>>m;
ll sum=0;
for(int i=1;i<=n;i++){
cin>>t[i].a>>t[i].b;
sum+=t[i].a;
}
sort(t+1,t+1+n);
int ans=0;
for(int i=1;i<=n;i++){
if(sum<=m) break;
sum-=t[i].a-t[i].b;
ans++;
}
if(sum<=m) cout<<ans<<endl;
else cout<<"-1"<<endl;
}
int main(){
int T=1;
//cin>>T;
while(T--){
solve();
}
return 0;
}
E
题意:略
题记:
C语言的sin函数需要传递的是弧度,弧度=角度*pi/180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
int main(){
double n,r;
cin>>n>>r;
double s=sin(360/(n*2)*(pi/180));
double ans=(s*r)/(1-s);
printf("%.8f\n",ans);
return 0;
}
F
G
边栏推荐
- The configuration and options of save actions are explained in detail, and you won't be confused after reading it
- VSCode+mingw64+cmake
- Upload taro pictures to Base64
- Colorbar of using vertexehelper to customize controls (II)
- 如何使用clipboard.js库实现复制剪切功能
- Unity shader (data type in cghlsl)
- How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
- 信息安全实验二 :使用X-SCANNER扫描工具
- (3/8) method parameters of improper use of enumeration (2)
- Elaborate on MySQL mvcc multi version control
猜你喜欢

VSCode+mingw64

Jenkins modifies the system time

H5网页播放器EasyPlayer.js如何实现直播视频实时录像?

12、 Sort

First issue of JS reverse tutorial

Information Security Experiment 4: implementation of IP packet monitoring program

面试被问到了解哪些开发模型?看这一篇就够了

PLC信号处理系列之开关量信号防抖FB

Arthas simple instructions

Regular matching starts with XXX and ends with XXX
随机推荐
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
thinkphp数据库的增删改查
Redis common commands
AI从感知走向智能认知
第一讲:寻找矩阵的极小值
Liunx command
在EXCEL写VBA连接ORACLE并查询数据库中的内容
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
牛客网——华为题库(61~70)
Network request process
STM32 and motor development (from stand-alone version to Networking)
Niuke - Huawei question bank (61~70)
消费互联网的产业链其实是很短的,它仅仅承接平台上下游的对接和撮合的角色
網易雲微信小程序
Yapi test plug-in -- cross request
Detailed explanation of diffusion model
Colorbar of using vertexehelper to customize controls (II)
Unity shader (basic concept)
The difference between viewpager2 and viewpager and the implementation of viewpager2 in the rotation chart
Loxodonframework quick start