当前位置:网站首页>2019腾讯暑期实习生正式笔试
2019腾讯暑期实习生正式笔试
2022-07-06 09:14:00 【极客云曦】
找规律,如果1+2可以表示3以内所有数,1+2+4表示7以内所有数,1+2+4+8表示15以内所有数,,,规律:a[n]<=sum[1~n-1]+1时,可以表示sum[1~n]内所有数
AC代码
第二题跟01位置无关,直接统计个数
#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;
}
边栏推荐
- 学习问题1:127.0.0.1拒绝了我们的访问
- Windows下安装MongDB教程、Redis教程
- PHP - whether the setting error displays -php xxx When PHP executes, there is no code exception prompt
- L2-007 家庭房产 (25 分)
- ES6 let and const commands
- MySQL与c语言连接(vs2019版)
- 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
- Codeforces Round #771 (Div. 2)
- 基于apache-jena的知识问答
- error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
猜你喜欢
Windows下安装MongDB教程、Redis教程
QT creator design user interface
Valentine's Day flirting with girls to force a small way, one can learn
QT creator custom build process
QT creator test
Classes in C #
QT creator support platform
学习问题1:127.0.0.1拒绝了我们的访问
打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
Did you forget to register or load this tag 报错解决方法
随机推荐
QT creator custom build process
L2-001 紧急救援 (25 分)
Codeforces Round #753 (Div. 3)
LeetCode #461 汉明距离
AcWing 179. Factorial decomposition problem solution
图片上色项目 —— Deoldify
MySQL and C language connection (vs2019 version)
Solve the problem of installing failed building wheel for pilot
Nanny level problem setting tutorial
L2-006 树的遍历 (25 分)
Use dapr to shorten software development cycle and improve production efficiency
使用lambda在循环中传参时,参数总为同一个值
Punctual atom stm32f103zet6 download serial port pin
Reading BMP file with C language
Vs2019 desktop app quick start
Why can't I use the @test annotation after introducing JUnit
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
Introduction to the easy copy module
One click extraction of tables in PDF
UDS learning notes on fault codes (0x19 and 0x14 services)