当前位置:网站首页>2019 Tencent summer intern formal written examination
2019 Tencent summer intern formal written examination
2022-07-06 11:36:00 【Geek Yunxi】

Looking for a regular , If 1+2 Can be said 3 All numbers within ,1+2+4 Express 7 All numbers within ,1+2+4+8 Express 15 All numbers within ,,, law :a[n]<=sum[1~n-1]+1 when , Can be said sum[1~n] All numbers in
AC Code


The second question follows 01 Position is irrelevant , Directly count the number
#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;
}
边栏推荐
- Neo4j installation tutorial
- Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
- [Bluebridge cup 2021 preliminary] weight weighing
- Request object and response object analysis
- Introduction and use of automatic machine learning framework (flaml, H2O)
- Case analysis of data inconsistency caused by Pt OSC table change
- Library function -- (continuous update)
- Why can't STM32 download the program
- Database advanced learning notes -- SQL statement
- error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
猜你喜欢

02 staff information management after the actual project

MySQL and C language connection (vs2019 version)

Double to int precision loss
C语言读取BMP文件
![[Flink] Flink learning](/img/2e/ff53e0795456e301f61da908c013af.png)
[Flink] Flink learning

Case analysis of data inconsistency caused by Pt OSC table change

QT creator support platform

MongoDB

解决安装Failed building wheel for pillow

Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
随机推荐
nodejs连接Mysql
L2-007 家庭房产 (25 分)
误删Path变量解决
Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
Codeforces Round #753 (Div. 3)
机器学习笔记-Week02-卷积神经网络
[CDH] modify the default port 7180 of cloudera manager in cdh/cdp environment
MySQL and C language connection (vs2019 version)
4. Install and deploy spark (spark on Yan mode)
[Bluebridge cup 2020 preliminary] horizontal segmentation
[Presto] Presto parameter configuration optimization
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
数据库面试常问的一些概念
Vs2019 use wizard to generate an MFC Application
MySQL与c语言连接(vs2019版)
Kept VRRP script, preemptive delay, VIP unicast details
[yarn] yarn container log cleaning
PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
快来走进JVM吧
jS数组+数组方法重构