题解分享
题解分享简介
合并数列(编程题) - 题解
emmmm既然要最后两个数组一样 那么他们的长度必须一样,而且只能有合并操作,那么合并一次长度减一,在第二个数组不进行合并的情况下,直接用两个数组长度相减就是答案。而且由题目可以得到,第二个数组不进行任何操作的情况也是正解
```
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef struct point{
int x;
int y;
}point;
int main(){
int n,m;
cin>>n>>m;
int arr[n+10];
int brr[m+10];
for(int i=1;i<=n;i++)
cin>>arr[i];
for(int j=1;j<=m;j++)
cin>>brr[j];
cout<<abs(n-m)<<endl;
return 0;
}
```
查看全文
3
0
0
7
合并数列(编程题) - 题解
直接模拟即可, 代码很简单, 你一定能看明白的
```cpp
#include <cstdio>
#include <list>
using namespace std;
int main() {
int res = 0;
int n = 0, m = 0;
scanf("%d %d", &n, &m);
list<int> arr;
list<int> brr;
for (int i = 0, j; i < n; ++i) {
scanf("%d", &j);
arr.push_back(j);
}
for (int i = 0, j; i < m; ++i) {
scanf("%d", &j);
brr.push_back(j);
}
while (arr.size() && brr.size()) {
if (*arr.rbegin() == *brr.rbegin()) {
arr.pop_back();
brr.pop_back();
} else {
++res;
if (*arr.rbegin() > *brr.rbegin()) {
// 合并 brr 的
int x = *brr.rbegin();
brr.pop_back();
int& y = *brr.rbegin();
y += x;
} else {
// 合并 arr 的
int x = *arr.rbegin();
arr.pop_back();
int& y = *arr.rbegin();
y += x;
}
}
}
printf("%d\n", res);
return 0;
}
```
查看全文
0
0
1
1
合并数列(编程题) - 题解
```
#include <bits/stdc++.h>
using namespace std;
queue<int> a, b;
signed main(){
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; ++i){
int x; cin >> x;
a.push(x);
}
for(int i = 1; i <= m; ++i){
int x; cin >> x;
b.push(x);
}
int cnt = 0;
while(a.size() || b.size()){
int top1 = a.front(), top2 = b.front();
a.pop(), b.pop();
while(top1 != top2){
if(top1 < top2){
top1 += a.front();
++cnt;
a.pop();
}else{
top2 += b.front();
++cnt;
b.pop();
}
}
}
cout << cnt << endl;
return 0;
}
```
查看全文
0
0
0
1
合并数列(编程题) - 题解
include
define int long long
using namespace std;
int n,m,ans=0;
int a[100001],b[100001];
```
`
```
````
signed main()
{
cin >>n>>m;
for(int i=0;i
b[j])//同理
{
j++;
ans++;
if(j<m)
b[j]+=b[j-1];
}
}
cout <<ans<<endl;
return 0;
}
查看全文
0
0
0
1



