AtCoder Beginner Contest 203(Sponsored by Panasonic)

Updated:

A. Chinchirorin

a,b,c가 주어질 때, 입력된 수 중 2개가 겹친다면 나머지 하나를 출력하고 아무것도 겹치지 않는다면 0을 출력하는 문제이다.

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=1e10+1;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  //freopen("input.txt","r",stdin);
  int a,b,c;
  cin>>a>>b>>c;
  int ans=0;
  if(a==b|b==c|a==c) ans=a^b^c;
  cout<<ans;
  return 0;
}

B. AtCoder Condominium

ij번째 방은 i0j호로 표시되는데 주어지는 N, K에 대해 1층부터 N층까지 K개의 방의 호수를 전부 더했을 때 나오는 결과를 출력하는 문제이다.

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=1e10+1;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  //freopen("input.txt","r",stdin);
  int n,k;
  cin>>n>>k;
  int sum=0;
  for(int i=1;i<=n;i++) {
    for(int j=1;j<=k;j++) sum+=(i*100+j);
  }
  cout<<sum;
  return 0;
}

C. Friends and Travel costs

Taro가 최대 $10^{100}-1$개의 마을을 여행하려고 한다. Taro는 0번째 마을부터 시작하고 마을을 방문할 때는 1엔을 지불해야 한다.

Taro는 $A_i$번째 마을에 $i$ 친구가 있어 $B_i$엔을 받을 수 있다. 이 돈으로 다시 여행을 갈 수 있다.

이때, Taro가 최대한 갈 수 있는 마을은 몇 번째인지 계산하는 문제이다.

친구 N의 범위는 $1≤N≤2\times10^5$이고 $1≤A_i≤10^{18}$, $1≤B_i≤10^9$의 범위를 가지고 있다.

Taro의 소지금은 K이므로 중간에 아무 친구도 만나지 못할 때 K번째 마을까지 갈 수 있다는 의미가 된다.

만약 중간에 친구를 만나 B엔을 받았다면 추가로 받은 돈만큼 다시 여행을 갈 수 있다.

즉, 현재 갈 수 있는 최대 거리안에 친구에게 돈을 받고 그 돈만큼 최대 거리를 늘리는 방법으로 구현해야 한다.

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=1e10+1;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  //freopen("input.txt","r",stdin);
  ll n,k;
  cin>>n>>k;
  vector<pll> v(n);
  for(int i=0;i<n;i++) {
    cin>>v[i].first>>v[i].second;
  }
  sort(v.begin(),v.end());
  ll ans=k;
  for(int i=0;i<n;i++) {
    if(ans>=v[i].first) ans+=v[i].second;
  }
  cout<<ans;
  return 0;
}

Tags:

Categories:

Updated:

Leave a comment