https://www.acmicpc.net/problem/15954



이번 문제는 너무 멍청하게 풀었네요. 속도가 많이 느립니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    int N, K;
    int doll[500];
    long double ret = 2147483647;
    
    cin >> N >> K;
    
    for(int i = 0; i < N; i++cin >> doll[i];
 
    for(int i = 0; i < N; i++){
        
        
        for(int k = 0; k + K <= N; k++){
            bool chk = true;
            long double m = 0;
            long double t = 0;
            for(int j = i; j < i+K+k; j++){
                if(i+K+> N) {chk= falsebreak;}
                m+=doll[j];
            }
            m /= K+k;
        
        
            for(int j = i; j < i+K+k; j++){
                if(i+K+> N){chk = falsebreak;}
                t+=((doll[j]-m)*(doll[j]-m));
            }
            t /=K+k;
        
            if(chk)ret = min(ret,sqrt(t));
        }
    }
    cout << fixed; cout.precision(11);
    cout << ret;
}
cs


반응형

https://www.acmicpc.net/problem/9461


그림을 보면 금방 규칙을 찾을 수 있습니다.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,T;
    long long dp[100= {1,1,1,2,2};
    for(int i = 5; i < 100; i++) dp[i] = dp[i-1+ dp[i-5];
    
    cin >> T;
    
    while(T--){
        cin >> n;
        cout << dp[n-1<< endl;
    }
}
cs


반응형

https://www.acmicpc.net/problem/2164


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <list>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    list<int> card;
    int N;
    
    cin >> N;
    for(int i = 1; i <= N; i++)
        card.push_back(i);
    
    while(1){
        if(card.size() != 1) {
            card.pop_front();
            card.push_back(card.front());
            card.pop_front();
        }
        else break;
    }
    
    cout << card.front();
}
cs


반응형

https://www.acmicpc.net/problem/4949




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <stack>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    while(1){
        string s;
        stack<char> st;
        bool chk = true//yes or no
        
        getline(cin, s);
        
        if(s[0== '.'break;
        
        int len = s.length();
        
        for(int i = 0; i < len; i++){
            if(s[i] == '(' || s[i] == '[') st.push(s[i]);
            else if(s[i] == ')'){
                if(st.empty() || st.top() == '['){
                    chk = false;
                    break;
                }
                else st.pop();
            }
            else if(s[i] == ']'){
                if(st.empty() || st.top() == '('){
                    chk = false;
                    break;
                }
                else st.pop();
            }
        }
        
        if(chk && st.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
}
cs


반응형

https://www.acmicpc.net/problem/1085


직각이 되는 거리가 제일 짧다는 것을 생각하고 풀었습니다.


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    int x,y,w,h;
    
    cin >> x >> y >> w >> h;
    
    cout << min(w-x,min(x,min(y,h-y)));
}
 
cs


반응형

'프로그래밍 > 문제풀이' 카테고리의 다른 글

[etc] 백준 2164 카드2  (0) 2018.12.11
[스택] 백준 4949 균형잡힌 세상  (0) 2018.12.11
[etc] 백준 1436 영화감독 숌  (0) 2018.12.10
[etc] 백준 10809 알파벳 찾기  (0) 2018.12.10
[etc] 백준 1946 신입 사원  (0) 2018.12.09

https://www.acmicpc.net/problem/1436


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, cnt = 0, num = 665;
    
    cin >> n;
    
    while(cnt != n){
        int tmp = 0;
        num++;
        string s = to_string(num);
        
        for(int i = 0; i < s.size(); i++){
            if(tmp ==3break;
            
            if(s[i] == '6'){
                if(tmp==0) tmp +=1;
                else if(s[i-1== '6') tmp+=1;
                else tmp = 0;
            }
            else tmp = 0;
        }
        
        if(tmp == 3) cnt++;
        
    }
    cout << num;
}
cs



너무 무식하게 풀었네요

반응형

https://www.acmicpc.net/problem/10809


쉬웠습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string s;
    int arr[26= {0};
    
    cin >> s;
    
    for(int i = 0; i < s.size(); i++){
        if(!arr[s[i]-97]) arr[s[i]-97= i+1;
    }
    
    for(int i = 0; i < 26; i++){
        if(arr[i] == 0cout << -1 << ' ';
        else            cout << arr[i]-1 << ' ';
    }
}
cs


반응형

https://www.acmicpc.net/problem/1946




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int T,N,ret,tmp;
    pair<int,int> p[100000];
    
    cin >> T;
    
    for(int i = 0; i < T; i++){
        
        cin >> N;
        
        for(int j = 0; j < N; j++)
            cin >> p[j].first >> p[j].second;
        
        sort(p,p+N);
        
        ret = 1;
        tmp = p[0].second;
        for(int j = 1; j < N; j++){
            if(tmp > p[j].second){
                ret++;
                tmp = p[j].second;
            }
        }
            
        cout << ret << endl;
        
    }
    
}
cs


반응형

'프로그래밍 > 문제풀이' 카테고리의 다른 글

[etc] 백준 1436 영화감독 숌  (0) 2018.12.10
[etc] 백준 10809 알파벳 찾기  (0) 2018.12.10
[etc] 백준 1049 기타줄  (0) 2018.12.07
[etc] 백준 1931 회의실 배정  (0) 2018.12.07
[bfs] 백준 13460 구슬 탈출2  (0) 2018.11.28

https://www.acmicpc.net/problem/1049


보통 기타줄은 6개라서, 최대로 구입할 줄이 6개인줄 알아서 틀렸었습니다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    int N,M;
    int pac = 1001, pce= 1001
    cin >> N >> M;
    int tmp;
    for(int i = 0; i < M; i++){
        cin >> tmp;
        pac = min(tmp,pac);
        cin >> tmp;
        pce = min(tmp, pce);
    }
    
    cout << min(N/6 * pac + N%6 * pce, min(pce * N,N/6*pac+pac));
}
cs


반응형

'프로그래밍 > 문제풀이' 카테고리의 다른 글

[etc] 백준 10809 알파벳 찾기  (0) 2018.12.10
[etc] 백준 1946 신입 사원  (0) 2018.12.09
[etc] 백준 1931 회의실 배정  (0) 2018.12.07
[bfs] 백준 13460 구슬 탈출2  (0) 2018.11.28
[etc] 백준 13456 시험 감독  (0) 2018.11.26

https://www.acmicpc.net/problem/1931


종료시간으로 오름차순 정렬을 합니다.

만약 종료시간이 같은 경우에는 시작 시간이 더 빠른 것이 앞에 옵니다.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    pair<int,int> p[100000];
    int N;
    
    cin >> N;
    
    for(int i = 0; i < N; i++)
        cin >> p[i].second>> p[i].first;
    
    sort(p,p+N);
    
    int cnt = 0;
    int end = 0;
    for(int i = 0; i < N; i++){
        if(end <= p[i].second){
            end = p[i].first;
            cnt++;
        }
    }
    
    cout << cnt;
}
 
 
cs


반응형

'프로그래밍 > 문제풀이' 카테고리의 다른 글

[etc] 백준 1946 신입 사원  (0) 2018.12.09
[etc] 백준 1049 기타줄  (0) 2018.12.07
[bfs] 백준 13460 구슬 탈출2  (0) 2018.11.28
[etc] 백준 13456 시험 감독  (0) 2018.11.26
[bfs] 백준 16234 인구 이동  (0) 2018.11.24

+ Recent posts