当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Vs2019 desktop app quick start
Software I2C based on Hal Library
4. Install and deploy spark (spark on Yan mode)
Django running error: error loading mysqldb module solution
02 staff information management after the actual project
Did you forget to register or load this tag
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead
Learning question 1:127.0.0.1 refused our visit
Face recognition_ recognition
第4阶段 Mysql数据库
随机推荐
L2-006 树的遍历 (25 分)
第4阶段 Mysql数据库
wangeditor富文本组件-复制可用
QT creator uses Valgrind code analysis tool
Did you forget to register or load this tag
MySQL与c语言连接(vs2019版)
L2-006 tree traversal (25 points)
Wangeditor rich text component - copy available
软件测试与质量学习笔记3--白盒测试
Mysql的索引实现之B树和B+树
Summary of numpy installation problems
express框架详解
Codeforces Round #771 (Div. 2)
4. Install and deploy spark (spark on Yan mode)
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_ s instead
vs2019 第一个MFC应用程序
分布式节点免密登录
Django running error: error loading mysqldb module solution
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks