日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 拼手速题2

發(fā)布時(shí)間:2025/4/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 拼手速题2 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

?

?

題目鏈接:    https://codeforces.com/problemset/problem/1141/C

?

?

C. Polycarp Restores Permutation time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output An array of integers p1,p2,…,pnp1,p2,…,pn is called a permutation if it contains each number from 11 to nn exactly once. For example, the following arrays are permutations: [3,1,2][3,1,2], [1][1], [1,2,3,4,5][1,2,3,4,5] and [4,3,1,2][4,3,1,2]. The following arrays are not permutations: [2][2], [1,1][1,1], [2,3,4][2,3,4].Polycarp invented a really cool permutation p1,p2,…,pnp1,p2,…,pn of length nn. It is very disappointing, but he forgot this permutation. He only remembers the array q1,q2,…,qn?1q1,q2,…,qn?1 of length n?1n?1, where qi=pi+1?piqi=pi+1?pi.Given nn and q=q1,q2,…,qn?1q=q1,q2,…,qn?1, help Polycarp restore the invented permutation.Input The first line contains the integer nn (2≤n≤2?1052≤n≤2?105) — the length of the permutation to restore. The second line contains n?1n?1 integers q1,q2,…,qn?1q1,q2,…,qn?1 (?n<qi<n?n<qi<n).Output Print the integer -1 if there is no such permutation of length nn which corresponds to the given array qq. Otherwise, if it exists, print p1,p2,…,pnp1,p2,…,pn. Print any such permutation if there are many of them.
Examples

input
3 -2 1 output 3 1 2

input
5 1 1 1 1 output 1 2 3 4 5

input
4 -1 2 2 output -1

?

?

題意:? ? ?輸入整數(shù)n? ,在輸入n-1個(gè)數(shù),代表著目標(biāo)數(shù)組后一個(gè)減前一個(gè)數(shù)組的差的值,  即: ans[i+1] - ans[i]

    若存在則輸出數(shù)組ans的值      若不存在則輸出-1

?

?

思路:  暴力水題。。。。。。。。。。。。。。

?

#include<iostream> #include<cstdio> #include<ctime> #include<cstring> #include<cstdlib> #include<cmath> #include<queue> #include<stack> #include<map> #include<algorithm> #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a)<(b)?(a):(b)) #define Mem0(x) memset(x,0,sizeof(x)) #define Mem1(x) memset(x,-1,sizeof(x)) #define MemX(x) memset(x,0x3f,sizeof(x)) using namespace std; typedef long long ll; const int inf=0x3f3f3f; const double pi=acos(-1.0);ll ans[2000010],q[2000010],cnt[2000010],n; int main() {memset(cnt,0,sizeof(cnt));scanf("%lld",&n);ll tmp=0,l=0;for (int i=1;i<n;i++){scanf("%lld",&q[i]);l+=q[i]; tmp=tmp+l;}ll temp=(n+1)*n/2;ll pp=temp-tmp;bool flag=false;temp=pp/n;for (int i=1;i<=n;i++){ans[i]=temp;if (temp<=0||temp>n||cnt[ans[i]]>=1){flag=true;}else{cnt[ans[i]]++;}temp=temp+q[i];}if (flag)printf("-1");else{for (int i=1;i<=n;i++){printf("%lld ",ans[i]);}}printf("\n");return 0; }

  

?

轉(zhuǎn)載于:https://www.cnblogs.com/q1204675546/p/10951678.html

總結(jié)

以上是生活随笔為你收集整理的codeforces 拼手速题2的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。