1. 程式人生 > >Atcoder-SoundHound Inc.Contest 2018 -Masters Tournament-比賽報告

Atcoder-SoundHound Inc.Contest 2018 -Masters Tournament-比賽報告

template names 需要 fine temp oid get min inline

A

C++ Example

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)puts("+");
  else if(a*b==15)puts("*");
  else puts("x");
  return 0;
}

B

C++ Example

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
const int maxn=100000;
char str[maxn];
int main(){
  int w;
  scanf("%s",str);
  scanf("%d",&w);
  if(w==1){printf("%s",str);return 0;}
  for(int i=0;i<strlen(str);i++){
      if(i%w==0){
          putchar(str[i]);
      }
  }
  return 0;
}

C

這題畫風突變啊餵

這題我比較SB打表沒找出規律還是yjw學長點醒了我 \(yjw\)學長 \(orz\)

這題其實是個概率題,長度為\(m\),則最多有\(m-1\)對數字,顯然每一對之間是互相不影響的,於是我們先來研究一對數字的情況:

首先每個數字都有n個數字與之配對,總計\(n × n\)種情況,再考慮對答案做貢獻的,假設那一對數字是\(x,y (y>x)\),則能做貢獻的情況有\(n-d\)種.當然我們這只是\(x<y\)的情況,所以共\(2×(n-d)\)種。當然\(d==0\)時,就無關大小,只有\((n-d)\)種,這需要特判.

然後交上去還是\(WA\)了,發現強制類型轉換寫在括號外導致會爆\(int\)

,比較坑

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#define ri register int 
using namespace std;
template <class T>void read(T &x){
  x=0;int ne=0;char c;
  while(!isdigit(c=getchar()))ne=c==‘-‘;
  x=c-48;
  while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
  x=ne?-x:x;
  return ;
} 
int n,m,d;
int main(){
  read(n),read(m),read(d);
  if(d==0)printf("%.10Lf\n",(long double)(m-1)/n);
  else if(n<=d)printf("0.0000000\n");
  else printf("%.10Lf\n",(long double)(1.00*2*(n-d)*(m-1))/n/n);
  return 0;
}

D

這題解法很有意思,比較考驗智商

求兩個最短路,一個是\(s\)\(x (x \in [1,n])\)的用\(yen\)衡量的最短路\(dis_1(s,x)\),一個是從\(t\)\(x (x \in [1,n])\)的最短路\(dis_2(t,x)\),用\(snuuk\)衡量的最短路

然後我們想,最後\(n-1\)年出發的時候只用\(n\)這個點可以交換貨幣,所以\(val[n-1]=dis_1(s,n)+dis_2(t,n)\)

再向下想,在\(n-2\)年出發時,要麽繼續到\(n\)這個點交換貨幣,要麽到\(n-1\)這個點交換貨幣,以此類推得到

\(val[p]=min(val[p+1],dis_1(s,p)+dis_2(t,p)) p \in [0,n-1]\)

最後初始錢數\(-val\)值就是對應答案

E

我太菜不知道怎麽做,等待咕咕咕的題解吧

Atcoder-SoundHound Inc.Contest 2018 -Masters Tournament-比賽報告