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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #201 (Div. 2)C,E

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #201 (Div. 2)C,E 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數論: C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of?n?distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers?x?and?y?from the set, such that the set doesn't contain their absolute difference?|x?-?y|. Then this player adds integer?|x?-?y|?to the set (so, the size of the set increases by one).

If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

Input

The first line contains an integer?n?(2?≤?n?≤?100) — the initial number of elements in the set. The second line contains?n?distinct space-separated integers?a1,?a2,?...,?an?(1?≤?ai?≤?109) — the elements of the set.

Output

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

Examples input 2
2 3 output Alice input 2
5 3 output Alice input 3
5 6 7 output Bob Note

Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

?題意:

兩人游戲,最初給出n個數集合當輪到一個人時他要從中選兩個數x,y,使得|x-y|不在集合中,然后把|x-y|加進集合。當沒法挑選時輸。Alice先Bob后。

代碼:

//并非1~n的每一個數都能得到。得到的數只可能是最初的n個數的最大公約束數的倍數。 //因為不斷地作減法可以看成求gcd的運算,最終減到的最小的數就是他們的gcd. #include<bits/stdc++.h> using namespace std; int n,a[100005],c[100005]; int main() {cin>>n;int cnt=0,flag=0;for(int i=0;i<n;i++) cin>>a[i];for(int i=0;i<n;i++){if(a[i]==i) cnt++;else if(a[a[i]]==i) flag=1;}if(cnt==n) cout<<cnt<<endl;else if(flag) cout<<cnt+2<<endl;else cout<<cnt+1<<endl;return 0; } 貪心 dp E. Number Transformation II time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

You are given a sequence of positive integers?x1,?x2,?...,?xn?and two non-negative integers?a?and?b. Your task is to transform?a?into?b. To do that, you can perform the following moves:

  • subtract 1 from the current?a;
  • subtract?a?mod?xi?(1?≤?i?≤?n)?from the current?a.

Operation?a?mod?xi?means taking the remainder after division of number?a?by number?xi.

Now you want to know the minimum number of moves needed to transform?a?into?b.

Input

The first line contains a single integer?n?(1?≤??n?≤?105). The second line contains?n?space-separated integers?x1,?x2,?...,?xn?(2?≤??xi?≤?109). The third line contains two integers?a?and?b?(0??≤?b?≤??a?≤?109,?a?-?b?≤?106).

Output

Print a single integer — the required minimum number of moves needed to transform number?a?into number?b.

Examples input 3
3 4 5
30 17 output 6 input 3
5 6 7
1000 200 output 206

?題意:

給出n個數x[1...n]和a,b問從a變到b的最少步數。a每次可以減1或者減a%x[i]。

代碼:

//每次減去1和a%x[i](0<=i<=n-1)中大的那個,直到a<=b。 //剪枝:x數組去重;顯然如果a-a%x[i]<b,x[i]就可以去掉,下次不用計算他了 #include<bits/stdc++.h> using namespace std; int n,num[100005],a,b; int main() {cin>>n;for(int i=0;i<n;i++) cin>>num[i];cin>>a>>b;sort(num,num+n);int len=unique(num,num+n)-num;int ans=0,tmp;while(a>b){tmp=a-1;for(int i=0;i<len;i++){int tmpp=a-a%num[i];if(tmpp<b) num[i--]=num[--len];else tmp=min(tmp,tmpp);}a=tmp;ans++;}cout<<ans<<endl;return 0; }

?

轉載于:https://www.cnblogs.com/--ZHIYUAN/p/6561790.html

總結

以上是生活随笔為你收集整理的Codeforces Round #201 (Div. 2)C,E的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。