本来计划着打这场的,快开始了,咳咳某人喊我打王者,没打成比赛,纯补题
简单模拟,只有几种情况下会有孤立的点,单列出来即可
#include
using namespace std;
#define db double
const int N = 2e5 + 10;
int T;
int n, m;
void solve(){
cin>>n>>m;
if(n == 1 || m == 1 || (n == 2 && m == 2)) cout<<"1 1"<<endl;\
else if(n == 2 && m == 3) cout<<"1 2"<<endl;
else if(n == 3 && m == 2) cout<<"2 1"<<endl;
else if(n == 3 && m == 3) cout<<"2 2"<<endl;
else cout<<"1 1"<<endl;
}
int main()
{
cin>>T;
while(T -- ){
solve();
}
return 0;
}
不是难题,简单思维,目测难度应该在800~1000
简单思维:差分数组逆推原数组,原数组的每个数都大于等于0,如果某一位存在两种情况,则不合条件输出-1(偷偷吐槽一下题中也没说原数组的元素可以等于0,不然还能一发入魂)
#include
using namespace std;
#define int long long
const int N = 2e5 + 10;
int T;
int n, m;
int a[N], d[N];
void solve(){
bool p = true;
cin>>n;
for(int i = 1; i <= n; i ++ ) cin>>d[i];
a[1] = d[1];
for(int i = 2; i <= n; i ++ ){
int a1 = a[i - 1] + d[i];
int a2 = a[i - 1] - d[i];
if(a2 >= 0 && a1 != a2){
p = false;
break;
}
a[i] = a1;
}
if(!p){
cout<<"-1"<<endl;
return ;
}
for(int i = 1; i <= n; i ++ ) cout<<a[i]<<' ';
cout<<endl;
}
signed main()
{
cin>>T;
while(T -- ){
solve();
}
return 0;
}