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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

2019CCPC-江西省赛(重现赛)- 感谢南昌大学

發(fā)布時(shí)間:2023/12/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019CCPC-江西省赛(重现赛)- 感谢南昌大学 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

趁著多校之際打了一下這個(gè)比賽,low的一批。做了七個(gè)題,被虐的不輕
Wave HDU - 6570
Avin is studying series. A series is called “wave” if the following conditions are satisfied:

  • It contains at least two elements;
  • All elements at odd positions are the same;
  • All elements at even positions are the same;
  • Elements at odd positions are NOT the same as the elements at even positions.
    You are given a series with length n. Avin asks you to find the longest “wave” subseries. A subseries is a subsequence of a series.
    Input
    The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a “wave” subseries.
    Output
    Print the length of the longest “wave” subseries.
    Sample Input
    5 3
    1 2 1 3 2
    Sample Output
    4
    首先,n很大,1e5。但是我們發(fā)現(xiàn)這個(gè)c很小。我們可以把每個(gè)數(shù)的位置記錄下來,枚舉每兩個(gè)數(shù)他們出現(xiàn)的位置,復(fù)雜度不是很大。
    代碼如下:
  • #include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<algorithm> #include<cmath> #define ll long long using namespace std;const int maxx=1e2+100; vector<int> p[maxx]; int n,m;int main() {while(scanf("%d%d",&n,&m)!=EOF){int x;for(int i=1;i<=m;i++) p[i].clear();for(int i=1;i<=n;i++){scanf("%d",&x);p[x].push_back(i);}int ans=0,maxn=0;int len1,len2,y;for(int i=1;i<=m;i++){for(int j=i+1;j<=m;j++){ans=0;len1=p[i].size();len2=p[j].size();x=y=0;int flag=0;if(p[i][0]<p[j][0]) flag=1;if(flag) x++;else y++;ans++;while(x<len1&&y<len2){if(flag==0){while(p[i][x]<p[j][y-1]&&x<len1) x++;if(x<len1){x++;ans++;flag=1;}else break;if(x==len1){while(y<len2){if(p[j][y]>p[i][x-1]){ans++;break; }y++;}break;}}else{//cout<<p[j][y]<<endl;while(p[j][y]<p[i][x-1]&&y<len2) y++;if(y<len2){y++;ans++;flag=0;}else break;if(y==len2){while(x<len1){if(p[i][x]>p[j][y-1]){ans++;break;}x++;}break;}}}maxn=max(maxn,ans);}}printf("%d\n",maxn);} }

    String HDU - 6572
    Avin has a string. He would like to uniform-randomly select four characters (selecting the same character is allowed) from it. You are asked to calculate the probability of the four characters being ”avin” in order.
    Input
    The first line contains n (1 ≤ n ≤ 100), the length of the string. The second line contains the string. To simplify the problem, the characters of the string are from ’a’, ’v’, ’i’, ’n’.
    Output
    Print the reduced fraction (the greatest common divisor of the numerator and denominator is 1), representing the probability. If the answer is 0, you should output “0/1”.
    Sample Input
    4
    avin
    4
    aaaa
    Sample Output
    1/256
    0/1
    很簡單的概率問題,數(shù)學(xué)純暴力
    代碼如下:

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> using namespace std;string s; int n;int gcd(int x,int y) {if(y==0) return x;else return gcd(y,x%y); } int main() {while(scanf("%d",&n)!=EOF){cin>>s;int cnt1=0;int cnt2=0;int cnt3=0;int cnt4=0;int len=s.length();for(int i=0;i<len;i++){if(s[i]=='a') cnt1++;else if(s[i]=='v') cnt2++;else if(s[i]=='i') cnt3++;else if(s[i]=='n') cnt4++;}len=len*len*len*len;int cnt=cnt1*cnt2*cnt3*cnt4;cnt1=gcd(cnt,len);printf("%d/%d\n",cnt/cnt1,len/cnt1);} }

    Traffic HDU - 6573
    Avin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars running in the north-south direction with the i-th car passing the intersection at time bi . If two cars passing the intersections at the same time, a traffic crash occurs. In order to achieve world peace and harmony, all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump. You are asked the minimum waiting time.
    Input
    The first line contains two integers n and m (1 ≤ n, m ≤ 1, 000). The second line contains n distinct integers ai (1 ≤ ai ≤ 1, 000). The third line contains m distinct integers bi (1 ≤ bi ≤ 1, 000).
    Output
    Print a non-negative integer denoting the minimum waiting time.
    Sample Input
    1 1
    1
    1
    1 2
    2
    1 3
    Sample Output
    1
    0
    狗題,一開始讀錯(cuò)題了,耽誤了好久。rng
    直接枚舉等待的時(shí)間,讓南北向的車都等待,去判斷是否可行。
    代碼如下:

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define ll long long using namespace std;const int maxx=5e3+100; bool vis1[maxx]; bool vis2[maxx]; int a[maxx]; int b[maxx]; int n,m;int main() {while(scanf("%d%d",&n,&m)!=EOF){memset(vis1,0,sizeof(vis1));memset(vis2,0,sizeof(vis2));for(int i=1;i<=n;i++) scanf("%d",&a[i]),vis1[a[i]]=1;for(int i=1;i<=m;i++) scanf("%d",&b[i]);for(int t=0;t<=3008;t++){memset(vis2,0,sizeof(vis2));for(int i=1;i<=m;i++){vis2[b[i]+t]=1;}int flag=0; for(int i=1;i<=t+100;i++){if(vis1[i]&&vis2[i]){flag=1;break;}}if(flag==0){printf("%d\n",t);break;}}} }

    Rng HDU - 6574
    Avin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly, and then generates another integer l between 1 and r (both inclusive) uniform-randomly. The interval [l, r] is then constructed. Avin has constructed two intervals using the method above. He asks you what the probability that two intervals intersect is. You should print p* q(?1)(MOD 1, 000, 000, 007), while pq denoting the probability.
    Input
    Just one line contains the number n (1 ≤ n ≤ 1, 000, 000).
    Output
    Print the answer.
    Sample Input
    1
    2
    Sample Output
    1
    750000006
    其實(shí)這個(gè)題就是瞎湊數(shù)。。。
    寫了一個(gè)求逆元的找出n=2的時(shí)候,是3/4。又自己手算了一遍n=3的時(shí)候是2/3也就是4/6。在我算n=4的時(shí)候,隊(duì)友猜了一個(gè)結(jié)論交上去了就過了orz。
    代碼如下:

    #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<vector> #include<functional> #define mod 9973 using namespace std; typedef long long ll; char s[100000+10]; long long int sum[100000+10]; ll gcd(ll a,ll b,ll &x,ll &y) {if(b==0){x=1;y=0;return a;}ll q=gcd(b,a%b,y,x);y-=a/b*x;return q; } ll cal(ll a,ll b,ll c) {ll x,y;ll g=gcd(a,b,x,y);if(c%g!=0) return -1;x*=c/g;b/=g;if(b<0) b=-b;ll ans=x%b;if(ans<=0) ans+=b;return ans; } ll qsm(ll a,ll b,ll c) {ll ans=1;ll res=a%c;while(b){if(b&1)ans*=res,ans%=c;res*=res;res%=c;b>>=1;}return ans%c; } int main () {ll n;while(cin>>n){cout<<((1+n)*cal(2ll*n,1000000007L,1L))%1000000007<<endl;}return 0; }

    Budget HDU - 6575
    Avin’s company has many ongoing projects with different budgets. His company records the budgets using numbers rounded to 3 digits after the decimal place. However, the company is updating the system and all budgets will be rounded to 2 digits after the decimal place. For example, 1.004 will be rounded down
    to 1.00 while 1.995 will be rounded up to 2.00. Avin wants to know the difference of the total budget caused by the update.
    Input
    The first line contains an integer n (1 ≤ n ≤ 1, 000). The second line contains n decimals, and the i-th decimal ai (0 ≤ ai ≤ 1e18) represents the budget of the i -th project. All decimals are rounded to 3 digits.
    Output
    Print the difference rounded to 3 digits…
    Sample Input
    1
    1.001
    1
    0.999
    2
    1.001 0.999
    Sample Output
    -0.001
    0.001
    0.000
    水題,但是還是錯(cuò)了一發(fā),(讀錯(cuò)題了rng)
    代碼如下:

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<cmath> #include<string> #define ll long long using namespace std;const int maxx=1e3+100; string s; int n;int main() {while(scanf("%d",&n)!=EOF){double ans=0.0;int len;for(int i=1;i<=n;i++){cin>>s;len=s.length();if(s[len-1]=='0') continue;else if(s[len-1]>='5'&&s[len-1]<='9') ans+=0.001*(10-s[len-1]+'0');else if(s[len-1]<'5'&&s[len-1]>'0') ans-=0.001*(s[len-1]-'0');}printf("%.3lf\n",ans);}return 0; }

    Worker HDU - 6576
    Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.
    Input
    The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.
    Output
    If there is a feasible assignment method, print “Yes” in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
    Otherwise, print “No” in one line. If there are multiple solutions, any solution is accepted.
    Sample Input
    2 6
    1 2
    2 5
    1 2
    Sample Output
    Yes
    4 2
    No
    提議挺簡單的,就是分配工人。但是一開始隊(duì)友最小公倍數(shù)求錯(cuò)了。GG了。多個(gè)數(shù)的最小公倍數(shù)就是先求兩個(gè)數(shù)的最小公倍數(shù),然后再和第三個(gè)數(shù)求最小公倍數(shù),依次下去。
    代碼如下:

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std;const int maxx=1e3+100; ll a[maxx]; int n; ll m;ll gcd(ll x,ll y) {if(y==0) return x;else return gcd(y,x%y); } int main() {while(scanf("%d%lld",&n,&m)!=EOF){for(int i=1;i<=n;i++) scanf("%lld",&a[i]);ll temp=a[1]*a[2]/gcd(a[1],a[2]);ll cgcd;for(int i=3;i<=n;i++){cgcd=gcd(temp,a[i]);temp=temp*a[i]/cgcd;}ll sum=0;for(int i=1;i<=n;i++) sum+=temp/a[i];if(sum>m||m%sum!=0){puts("No");continue;}puts("Yes");for(int i=1;i<=n;i++){printf("%lld",(temp/a[i])*(m/sum));if(i!=n) printf(" ");else printf("\n"); }} }

    Class HDU - 6577
    Avin has two integers a, b (1 ≤ a, b ≤ 1, 000).
    Given x = a + b and y = a - b, can you calculate ab?
    Input
    The first line contains two integers x, y.
    Output
    Print the result of ab.
    Sample Input
    4 2
    Sample Output
    3
    水的不能再水的解方程
    代碼如下:

    #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std;int main() {int x,y;cin>>x>>y;cout<<(x+y)*(x-y)/4<<endl;}

    A題的數(shù)據(jù)結(jié)構(gòu)題沒出出來。補(bǔ)完之后再發(fā)。
    努力加油a啊,(o)/~

    總結(jié)

    以上是生活随笔為你收集整理的2019CCPC-江西省赛(重现赛)- 感谢南昌大学的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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