1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

第二回日本最強プログラマー学生選手権 備忘録

Posted at

A - Competition

店1:1パック XgをY円で販売
店2:1パック Zg 店1よりg単価が安くなり、かつ最大の整数値段はいくらか?

それぞれの単価を出して、計算する。
Y/X*Zがちょい高くなるよう設定すればよい。
整数の時はそのまま出力だと同じ値段になるので1円足す。
割り切れない場合はそのまま出力。

# include <bits/stdc++.h>
# include <math.h>
using namespace std;

int main() {
  long double X,Y,Z;
  cin>>X>>Y>>Z;
  int A;
  long double B;
  int ans=0;
  A=Y/X*Z; //整数
  B=Y/X*Z; //浮動小数

  if(B>A){ //小数以下がある場合
  ans=(Y/X)*Z;
  }
  else{ //小数点以下がすべてゼロ
  ans=(Y/X)*Z-1;
  }
  
  if(ans<0){
    cout<<"0"<<endl;
  }
  else{ 
  cout<<ans<<endl;
  }
  }

B - Xor of Sequences
整数列 A,Bがある。
A, Bで片方にだけ出現する整数を、昇順に出力する。

map関数を使う。
A,Bそれぞれをmap Cにぶっこむ。
求めたい数字は1のやつだけを出力すればよい。
出力時に数字間の" "をわすれずに。

# include <bits/stdc++.h>
# include <math.h>
using namespace std;
 
int main() {
  int N,M;
  int A[1100];
  int B[1100];
  cin>>N>>M;
  map<int, int> C;
  for(int i=0;i<N;i++){
    cin>>A[i];
    C[A[i]]=C[A[i]]+1;
  }
  for(int i=0;i<M;i++){
    cin>>B[i];
    C[B[i]]=C[B[i]]+1;
  }
  for(int i=0;i<1001;i++){
    if(C[i]==1){
      cout<<i<<" ";
    }
  }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?