当前位置:网站首页>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;
}
边栏推荐
- Face recognition_ recognition
- 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
- MySQL与c语言连接(vs2019版)
- [Blue Bridge Cup 2017 preliminary] grid division
- Machine learning notes week02 convolutional neural network
- 搞笑漫画:程序员的逻辑
- Codeforces Round #753 (Div. 3)
- Word排版(小計)
- Pytoch Foundation
- L2-006 树的遍历 (25 分)
猜你喜欢

Connexion sans mot de passe du noeud distribué

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

How to build a new project for keil5mdk (with super detailed drawings)

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

【yarn】CDP集群 Yarn配置capacity调度器批量分配

double转int精度丢失问题

【flink】flink学习

软件测试与质量学习笔记3--白盒测试
![[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect](/img/e7/a0d4fc58429a0fd8c447891c848024.png)
[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect

分布式節點免密登錄
随机推荐
【CDH】CDH/CDP 环境修改 cloudera manager默认端口7180
[Blue Bridge Cup 2017 preliminary] buns make up
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
wangeditor富文本组件-复制可用
Software testing - interview question sharing
Vs2019 desktop app quick start
Mtcnn face detection
nodejs 详解
软件测试与质量学习笔记3--白盒测试
Vs2019 first MFC Application
解决安装Failed building wheel for pillow
【yarn】CDP集群 Yarn配置capacity调度器批量分配
【flink】flink学习
[AGC009D]Uninity
误删Path变量解决
Password free login of distributed nodes
Learn winpwn (3) -- sEH from scratch
QT creator test
Vs2019 use wizard to generate an MFC Application
DICOM: Overview