赞
踩
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int a[2000];
- int b[2000];
- int main(){
- int t;
- cin>>t;
- while(t--){
- int n;
- cin>>n;
- for(int i=1;i<=n-1;i++){
- cin>>b[i];
- }
- int x=1000000000;//使用1000000000这样在数据范围内绝对不会出现其他情况,一定是取余的数
- for(int i=n;i>=1;i--){
- a[i]=x;
- x-=b[i-1];
- }
- for(int i=1;i<=n;i++){
- cout<<a[i]<<" ";
- }
- cout<<endl;
- }
- system("pause");
- return 0;
- }
输入样例:
- 10
- 4 2 3 2
- 4 1 2 3
- 7 2 5 6
- 10 8 2 10
- 3 1 4 5 2 7 8 10 6 9
- 5 10 5 1 3 7 10 15 4 3
- 2 1000000000 1 2
- 1 2
- 4 4
- 8 10 4 1
- 5 1 4 3 2 8 6 7
- 1 1 2 1 2 100 101 102
- 5 1 2 5
- 1 2 4 5 3
- 4 6 9 4 2
- 4 2 3 1
- 4 1 3 2
- 6 8 5 3
- 6 9 5 4
- 6 1 3 5 2 4
- 6 9 8 9 5 10
- 4 8 4 2
- 2 3 4 1
- 5 2 8 7
- 4 2 3 1
- 4 1 3 2
- 6 8 5 3
- 2 1000000000 1 2
- 1 2
- 1000000000 2
输出样例:
- Bodya
- Sasha
- Draw
- Draw
- Bodya
- Sasha
- Sasha
- Sasha
- Sasha
- Bodya
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;//注意这道题一定要记得开long long
- ll a[200010];
- ll p[200030];
- int main(){
- ll t;
- cin>>t;
- while(t--){
- ll n,k,x,y;
- cin>>n>>k>>x>>y;
- for(int i=1;i<=n;i++){
- cin>>p[i];
- }
- for(int i=1;i<=n;i++){
- cin>>a[i];
- }
- ll X=0;
- ll Y=0;
- ll sx=0;
- ll sy=0;
- for(int i=0;i<min(n+1,k);i++){
- X=max(X,sx+(k-i)*a[x]);//相当于把每次的都记录上去所以可以放心更新
- sx+=a[x];
- x=p[x];
- Y=max(Y,sy+(k-i)*a[y]);
- sy+=a[y];
- y=p[y];
- }
- if(X>Y){
- cout<<"Bodya"<<endl;
- }else if(X<Y){
- cout<<"Sasha"<<endl;
- }else{
- cout<<"Draw"<<endl;
- }
- }
- system("pause");
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。