1. 程式人生 > >CF變紅之路_ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

CF變紅之路_ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

從今天開始刷CF,從round400 開始,div1,2,3都要做,並記錄自己的刷題進度,限時刷題(像比賽一樣)+ 補題, 以此記錄我的CF變紅之路。 A

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

typedef pair<string, string> Pair;

int main()
{
    //freopen("input.txt", "r", stdin);
    string a, b;
    cin >> a >> b;
    cout << a << " "
<< b << endl; Pair p(a, b); int n; scanf("%d", &n); while(n--) { cin >> a >> b; if(a==p.first) { p.first = b; } else if(a == p.second) { p.second = b; } else if(b == p.first) { p.first = a; } else
if(b == p.second) { p.second = a; } cout << p.first << " " << p.second << endl; } return 0; }

B

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

bool isprim(int n) {
    for(int i = 2; i <= sqrt(n); i++) {
        if(n % i == 0) return
false; } return true; } int main() { //freopen("input.txt", "r", stdin); int n; cin >> n; if(n <= 2) { cout << 1 << endl; } else cout << 2 << endl; int fir = 1; for(int i = 2; i <= n + 1; i++) { if(fir) { if (isprim(i)) { cout << 1 << endl; } else { cout << 2 << endl; } fir = 0; } else { if (isprim(i)) { cout << 1 << endl; } else { cout << 2 << endl; } fir = 0; } } return 0; }

C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = (int)1e5 + 10;
const ll inf = (ll)1e14;
ll sum[maxn];
map<ll, ll> mp;
set<ll> st;

int main() {
    //freopen("input.txt", "r", stdin);
    ll n, k;
    while(cin >> n >> k) {
        mp.clear();
        st.clear();
        sum[0] = 0;
        for(int i = 1; i <= n; i++) {
            scanf("%lld", &sum[i]);
            sum[i] += sum[i-1];
        }
        ll tmp = 1;
        st.insert(tmp);
        for(int i = 0; i <= 64; i++) {
            tmp *= k;
            if(tmp > inf) break;
            st.insert(tmp);
        }
        ll ans = 0;
        for(int i = 0; i <= n; i++) {
            for(set<ll>::iterator it = st.begin(); it != st.end(); it++) {
                ans += mp[sum[i] - *it];
            }
            mp[sum[i]]++;
        }
        cout << ans << endl;
    }
    return 0;
}

還有幾道題未補先佔個坑,剛開始做CF感覺題目思維量很大,需要大量練習才行。加油~