当前位置:网站首页>2019腾讯暑期实习生正式笔试
2019腾讯暑期实习生正式笔试
2022-07-06 09:14:00 【极客云曦】
找规律,如果1+2可以表示3以内所有数,1+2+4表示7以内所有数,1+2+4+8表示15以内所有数,,,规律:a[n]<=sum[1~n-1]+1时,可以表示sum[1~n]内所有数
AC代码
第二题跟01位置无关,直接统计个数
#include <bits/stdc++.h>
using namespace std;
int a[105];
typedef long long LL;
int n, m;
LL sum = 0;
int who(int i)
{
for(int j=i; j<n; j++)
{
if(a[j]>sum+1)
return j-1;
else if(a[j]==sum+1)
return j;
}
return n-1;
}
int main()
{
cin>>m>>n;
for(int i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
sort(a, a+n);
int ans= 0;
for(int i=0; i<n; i++)
{
int j = who(i);
i = j;
sum += a[j];
ans++;
if(sum >= m) break;
}
while(sum < m)
{
sum += a[n-1];
ans++;
}
printf("%d\n", ans);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, a = 0, b = 0;
cin>>n;
char s[200004];
scanf("%s", s);
int l = strlen(s);
for(int i=0; i<l; i++)
{
if(s[i]-'0' == 0) a++;
else b++;
}
cout<<abs(a-b)<<endl;
return 0;
}
边栏推荐
猜你喜欢
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
02-项目实战之后台员工信息管理
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
解决安装Failed building wheel for pillow
{一周总结}带你走进js知识的海洋
Picture coloring project - deoldify
Django running error: error loading mysqldb module solution
LeetCode #461 汉明距离
Leetcode 461 Hamming distance
Vs2019 first MFC Application
随机推荐
[download app for free]ineukernel OCR image data recognition and acquisition principle and product application
人脸识别 face_recognition
Solution to the practice set of ladder race LV1 (all)
Mtcnn face detection
Reading BMP file with C language
MySQL and C language connection (vs2019 version)
ES6 let and const commands
Vs2019 first MFC Application
Heating data in data lake?
Base de données Advanced Learning Notes - - SQL statements
Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
Niuke novice monthly race 40
jS数组+数组方法重构
TCP/IP协议(UDP)
[蓝桥杯2021初赛] 砝码称重
02-项目实战之后台员工信息管理
Attention apply personal understanding to images
Django运行报错:Error loading MySQLdb module解决方法
Learn winpwn (2) -- GS protection from scratch
Julia 1.6 1.7 common problem solving