ABC347
A
link

很简单
遍历,判断模\(k\)是否为\(0\),如果为\(0\),输出\(a_i/k\)。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[105];
signed main(){
cin >> n >> k;
for(int i = 1;i <= n;++ i){
cin >> a[i];
if(a[i]%k == 0) cout << a[i]/k << " ";
}
return 0;
}
B
link

前置知识:\(map\)
\(map\)类似数组,如\(a_b\),\(a\),\(b\)均可为任何类型,如字符串,大概意思就是,\(a\)对应\(b\)。
遍历每一个子串,看看这个子串在前面出没出现过,没出现过,答案加\(1\)。
怎样遍历子串。
首先两重循环,枚举子串的左右边界,在用一重循环,枚举在当前边界内每一个字符,组成子串。
怎样判断子串出没出过。
使用\(map\),看看\(map\)的当前字符串是否为\(1\),是,出现过,否,没出现过,答案加一,赋为\(1\),即出现过了。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
char s[105];
int n;
string t;
map<string,int> mp;
int ans;
signed main(){
cin >> s+1;
n = strlen(s+1);
for(int i = 1;i <= n;++ i){
for(int j = i;j <= n;++ j){
t.clear();
for(int k = i;k <= j;++ k){
t += s[k];
}
if(!mp[t]) mp[t] = 1,ans++;
}
}
cout << ans;
return 0;
}
C
link

首先,把每一个对应到第一周的上班日和第二周的休息日中。
那么只需要往后移动,把第一周上班日中的全移到第二周休息日,同时第二周休息日中的不能移出去。
找到这些中最大的和最小的(改后的数),如果大于休息日的时间,即会移出去,不可以。
还有一种方案,我们可以从前面截一段放到后面再判断。
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a,b;
int p[200005];
int d,ans = 1e18;
int ma,mi = 1e18;
signed main(){
cin >> n >> a >> b;
for(int i = 1;i <= n;++ i){
cin >> d;
d %= (a+b);
if(d == 0) d = a+b;
if(d <= a){
d += a+b;
}
ma = max(ma,d);
mi = min(mi,d);
p[i] = d;
}
sort(p+1,p+1+n);
for(int i = 1;i < n;++ i){
ans = min(ans,a+b-p[i+1]+p[i]+1);
}
ans = min(ans,ma-mi+1);
if(ans <= a) cout << "Yes";
else cout << "No";
return 0;
}
D
link

首先,我们定义一个\(cy\)为\(y\)中\(1\)的个数。
则,如果\(cy>a+b\),肯定不行。
如果\(cy=a+b\),把\(a\)个\(1\)给第一个数,\(b\)个\(1\)给第二个数,要对应到位置,即可。
如果\(cy<a+b\),\(a\)和\(b\)剩的是单数,不可以,双数可以。
双数的话,首先,在\(a\)和\(b\)中把多出来的平分去掉,剩下的把\(a\)个\(1\)给第一个数,\(b\)个\(1\)给第二个数,找够第一个和第二个数都是\(0\)的位置都赋成\(1\),即可。
注意不超过\(2^{60}\)。
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,cy;
int ca[65];
int aa[65],ba[65];
signed main(){
cin >> a >> b >> c;
int t = c;
for(int i = 0;i <= 59;++ i){
if(t&1) ca[i] = 1,cy++;
t >>= 1;
}
if(cy > a+b||(a+b-cy)%2 != 0){
cout << -1;
return 0;
}
int mu = (a+b-cy)/2;
a -= mu,b -= mu;
for(int i = 0;i <= 59;++ i){
if(ca[i]){
if(a) aa[i] = 1,a--;
else if(b) ba[i] = 1,b--;
}
}
if(a < 0||b < 0){
cout << -1;
return 0;
}
for(int i = 0;i <= 59;++ i){
if(!ca[i]){
if(mu){
aa[i] = 1;
ba[i] = 1;
mu--;
}
}
}
if(mu){
cout << -1;
return 0;
}
int y,e,w;
y = e = 0ll;
w = 1ll;
for(int i = 0;i <= 59;++ i){
if(aa[i]) y += w;
if(ba[i]) e += w;
w *= 2;
}
cout << y << " " << e << endl;
return 0;
}
随机推荐
- Prism IoC 依赖注入
现有2个项目,SinglePageApp是基于Prism创建的WPF项目,框架使用的是Prism.DryIoc,SinglePageApp.Services是C#类库,包含多种服务,下面通过使用Pri ...
- SMOGN算法Python实现:解决回归分析中的数据不平衡
本文介绍基于Python语言中的smogn包,读取.csv格式的Excel表格文件,实现SMOGN算法,对机器学习.深度学习回归中,训练数据集不平衡的情况加以解决的具体方法. 在不平衡回归问题 ...
- 拼多多面试:Netty如何解决粘包问题?
粘包和拆包问题也叫做粘包和半包问题,它是指在数据传输时,接收方未能正常读取到一条完整数据的情况(只读取了部分数据,或多读取到了另一条数据的情况)就叫做粘包或拆包问题. 从严格意义上来说,粘包问题和拆包 ...
- Win11 LTSC 中文版来了,丝般顺滑,极速响应
最近网络上出现了泄露的Win11的LTSC版本,版本号为Build 26100.1,据息,该泄露版是微软提供给OEM厂商测试用的,是今年下半年的Windows 11 LTSC RTM版的正式版本,却被 ...
- ts的keyof
keyof 是 TypeScript 中的一种类型操作符,用于获取一个类型的所有键(属性名)作为联合类型.它的语法如下: type KeysOfType = keyof ObjectType; 其中: ...
- taro 使用taro中的vue来完成小程序的开发
网址:https://taro-docs.jd.com/taro/docs/README 2.1.简介 Taro 是一个开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发 ...
- LeetCode 128. Longest Consecutive Sequence 最长连续序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of the longest consecutive elements sequenc ...
- P6259
problem 考虑使用 dfs 模拟. 由于一个程序可能在不进入无限循环的情况下运行很多步,这将会非常缓慢.因此,接下来要加速模拟,可以用记忆化搜索. 在网格中,机器人的可能状态(位置和朝向)只有 ...
- The remote name could not be resolved
HTTP The remote name could not be resolved HTTP Status:NameResolutionFailure
- C#.NET WINFORM 缓存 System.Runtime.Caching MemoryCache
C#.NET WINFORM 缓存 System.Runtime.Caching MemoryCache 工具类: using System; using System.Runtime.Caching ...