はやし屋

競技プログラミングのメモ きたない

AtCoder Beginner Contest #002

あ^~いいっすね^~

A.正直者
http://abc002.contest.atcoder.jp/tasks/abc002_1

めっちゃむずい

#include<iostream>
using namespace std;
int main(){
long long a , b ;cin >> a >> b;
cout << (a>b?a:b) << endl;
return 0;
}

B.罠
http://abc002.contest.atcoder.jp/tasks/abc002_2

めっちゃむずい

#include<iostream>     
#include<string>  
using namespace std;  
string s,t = "aiueo";

string solve(){
  string ret;
  for(int i = 0 ; i < s.size() ; ++i){
    if(!~t.find(s[i]))ret += s[i];
  }
  return ret;
}

int main(){
  cin >> s;
  cout << solve() << endl;
}

C.直訴
http://abc002.contest.atcoder.jp/tasks/abc002_3

めっちゃむずい

#include<iostream>     
#include<string>  
#include<cstdio>
#include<cmath>
using namespace std; 
 
int main(){
 
  double a,b ,c,d ,e,f ,p,q,r ,s,S;  
  cin >> a >> b >> c >> d >> e >> f;
  p = hypot(a-c,b-d);  
  q = hypot(a-e,b-f);  
  r = hypot(c-e,d-f);  
  s = (p+q+r) / 2;  
  S = sqrt(s*(s-p)*(s-q)*(s-r));
  printf("%lf\n",S); 
 
}

D.派閥
http://abc002.contest.atcoder.jp/tasks/abc002_4

めっちゃむずい

#include<iostream>     
#include<string>   
#include<cstdio>      
#include<algorithm>
#include<vector> 
using namespace std;  
 
int n , m;
bool g[555][555]={};
 
bool chk(vector < int > G){
  bool ret = true;
  for(int i = 0 ; i < G.size() ; ++i){
    for(int j = i+1 ; j < G.size() ; ++j){
      ret &= g[G[i]][G[j]];	
    }
  }
	
  return ret;
}
 
int solve(){
  int ret = 0;
  for(int bit = 0 ; bit < (1 << n) ; ++bit){
    vector < int > v;
    for(int i = 0 ; i < n ; ++i){
      if((bit >> i)&1){
	v.push_back(i);
      }
    }
    
    if(chk(v)){
      ret = max(ret,int(v.size()));
    }
    
  }
  return ret;
}
 
int main(){
  scanf("%d%d",&n,&m);
  for(int i = 0 ; i < m ; ++i){
    int a,b;scanf("%d%d",&a,&b);
    a--,b--;
    g[a][b] = g[b][a] = true;
  }
  printf("%d\n",solve());
}

ABCめっちゃむずかった