当前位置:网站首页>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;
}
边栏推荐
- AI benchmark V5 ranking
- Record a problem of raspberry pie DNS resolution failure
- Codeforces Round #771 (Div. 2)
- 记某公司面试算法题:查找一个有序数组某个数字出现的次数
- PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
- Project practice - background employee information management (add, delete, modify, check, login and exit)
- QT creator create button
- QT creator test
- Heating data in data lake?
- 软件测试-面试题分享
猜你喜欢

人脸识别 face_recognition

机器学习笔记-Week02-卷积神经网络

Introduction and use of automatic machine learning framework (flaml, H2O)

安装numpy问题总结

Valentine's Day flirting with girls to force a small way, one can learn

double转int精度丢失问题

Picture coloring project - deoldify

MTCNN人脸检测

Leetcode 461 Hamming distance
![[free setup] asp Net online course selection system design and Implementation (source code +lunwen)](/img/ac/b518796a92d00615cd374c0c835f38.jpg)
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
随机推荐
记某公司面试算法题:查找一个有序数组某个数字出现的次数
neo4j安装教程
AcWing 1294.樱花 题解
Install mongdb tutorial and redis tutorial under Windows
[蓝桥杯2021初赛] 砝码称重
Software testing and quality learning notes 3 -- white box testing
nodejs 详解
Aborted connection 1055898 to db:
wangeditor富文本引用、表格使用问题
Vs2019 use wizard to generate an MFC Application
02 staff information management after the actual project
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
JDBC原理
LeetCode #461 汉明距离
【kerberos】深入理解kerberos票据生命周期
ES6 Promise 对象
Cookie setting three-day secret free login (run tutorial)
Request object and response object analysis
Some notes of MySQL
Django运行报错:Error loading MySQLdb module解决方法