当前位置:网站首页>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;
}
边栏推荐
- L2-007 家庭房产 (25 分)
- yarn安装与使用
- L2-006 tree traversal (25 points)
- L2-001 紧急救援 (25 分)
- MATLAB学习和实战 随手记
- Django running error: error loading mysqldb module solution
- Solution to the practice set of ladder race LV1 (all)
- Nanny level problem setting tutorial
- 01 project demand analysis (ordering system)
- Picture coloring project - deoldify
猜你喜欢
随机推荐
MongoDB
Error connecting to MySQL database: 2059 - authentication plugin 'caching_ sha2_ The solution of 'password'
Solution to the practice set of ladder race LV1 (all)
AcWing 1298. Solution to Cao Chong's pig raising problem
Project practice - background employee information management (add, delete, modify, check, login and exit)
分布式節點免密登錄
[Presto] Presto parameter configuration optimization
[Blue Bridge Cup 2017 preliminary] grid division
double转int精度丢失问题
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
Knowledge Q & A based on Apache Jena
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation
数据库面试常问的一些概念
Picture coloring project - deoldify
[mrctf2020] dolls
Solve the problem of installing failed building wheel for pilot
【yarn】Yarn container 日志清理
About string immutability
Base de données Advanced Learning Notes - - SQL statements
AcWing 1294. Cherry Blossom explanation