跳到正文

题解

题解:P12006 【MX-X10-T2】[LSOT-4] 网易云

#SUSPENDED#约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年3月30日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 1 分钟
题目
P12006

版本

  1. v1当前

我们充分发扬人类智慧,把 11 和 22 作为第一首歌的好听值代入,看最后计算出的结果是否相等,若不相等则无法确定答案;否则就是计算出的答案。

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e5+5;
int n,m,a[maxn],q[maxn][2],ans,s[maxn];
signed main() {
	cin>>n>>m;
	for(int i=1;i<n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=m;i++)scanf("%lld%lld",&q[i][0],&q[i][1]);
	for(int i=1;i<=2;i++){
		int num=0;
		s[1]=i;
		for(int j=2;j<=n;j++)s[j]=a[j-1]-s[j-1];
//		for(int j=1;j<=n;j++)cout<<s[j]<<' ';
		for(int j=1;j<=m;j++)num+=s[q[j][0]]*q[j][1];
		if(i!=1&&ans!=num){
			cout<<"Impossible";return 0;
		}
		ans=num;
	}
	cout<<ans;
	return 0;
}
原文