当前位置:网站首页>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;
}
边栏推荐
- Punctual atom stm32f103zet6 download serial port pin
- 机器学习笔记-Week02-卷积神经网络
- vs2019 第一个MFC应用程序
- When using lambda to pass parameters in a loop, the parameters are always the same value
- 保姆级出题教程
- Basic use of redis
- Picture coloring project - deoldify
- Did you forget to register or load this tag
- Machine learning -- census data analysis
- Database advanced learning notes -- SQL statement
猜你喜欢
软件测试与质量学习笔记3--白盒测试
[蓝桥杯2017初赛]方格分割
基于apache-jena的知识问答
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
安装numpy问题总结
机器学习--人口普查数据分析
AcWing 1298. Solution to Cao Chong's pig raising problem
[Blue Bridge Cup 2017 preliminary] grid division
Integration test practice (1) theoretical basis
About string immutability
随机推荐
Vs2019 use wizard to generate an MFC Application
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
Django running error: error loading mysqldb module solution
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
C语言读取BMP文件
ImportError: libmysqlclient. so. 20: Cannot open shared object file: no such file or directory solution
LeetCode #461 汉明距离
One click extraction of tables in PDF
DICOM: Overview
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
Basic use of redis
Integration test practice (1) theoretical basis
[蓝桥杯2020初赛] 平面切分
L2-004 这是二叉搜索树吗? (25 分)
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
AcWing 1294. Cherry Blossom explanation
MySQL的一些随笔记录
软件测试-面试题分享
Summary of numpy installation problems
ES6 Promise 对象