当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
【CDH】CDH5.16 配置 yarn 任务集中分配设置不生效问题
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
Neo4j installation tutorial
机器学习笔记-Week02-卷积神经网络
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead
Double to int precision loss
Machine learning notes week02 convolutional neural network
[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect
Connexion sans mot de passe du noeud distribué
Learning question 1:127.0.0.1 refused our visit
随机推荐
AcWing 179.阶乘分解 题解
Codeforces Round #771 (Div. 2)
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
【Flink】CDH/CDP Flink on Yarn 日志配置
数据库面试常问的一些概念
How to set up voice recognition on the computer with shortcut keys
Test objects involved in safety test
Face recognition_ recognition
[mrctf2020] dolls
Heating data in data lake?
Why can't STM32 download the program
encoderMapReduce 随手记
What does BSP mean
[NPUCTF2020]ReadlezPHP
{一周总结}带你走进js知识的海洋
Punctual atom stm32f103zet6 download serial port pin
AcWing 1298.曹冲养猪 题解
L2-004 is this a binary search tree? (25 points)
Machine learning -- census data analysis
ES6 let 和 const 命令