夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

コードをはりつけるだけの簡単なお仕事

やります

PKU 2100

しゃくとりの実装はやっぱり手間取る…が、間違っているのは別のところだった

#include <cstdio>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n;
vector<P> res;
int main() {
    scanf("%lld",&n);
    int lb=0, ub=1;
    ll sum=0;
    while (true) {
        while (sum<n&&(ll)ub*(ll)ub<=n) {
            sum+=(ll)ub*ub;
            ub++;
        }
        if (sum<n) break;
        if (sum==n) res.push_back(P(lb+1,ub-1));
        lb++;
        sum-=(ll)lb*(ll)lb;
    }
    int rs=res.size();
    printf("%d\n",rs);
    for (int i=0; i<rs; i++) {
        printf("%d ",res[i].second-res[i].first+1);
        for (int j=res[i].first; j<=res[i].second; j++) {
            printf("%d%c",j,j==res[i].second?'\n':' ');
        }
    }
}

PKU 2160

#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int main() {
    map<int, int> mp;
    map<P, int> mpp;
    for (int i=0; i<6; i++) {
        int a, b;
        scanf("%d%d",&a,&b);
        if (mp.find(a)!=mp.end()) mp[a]++;
        else mp[a]=1;
        if (mp.find(b)!=mp.end()) mp[b]++;
        else mp[b]=1;
        if (a>b) swap(a,b);
        if (mpp.find(P(a,b))!=mpp.end()) mpp[P(a,b)]++;
        else mpp[P(a,b)]++;
    }
    map<int, int>::iterator itm;
    map<P, int>::iterator itmp;
    bool flag=true;
    for (itm=mp.begin(); itm!=mp.end(); itm++) {
        if ((*itm).second%4!=0) flag=false;
    }
    for (itmp=mpp.begin(); itmp!=mpp.end(); itmp++) {
        if ((*itmp).second%2!=0) flag=false;
    }
    if (flag) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}

PKU 3239

むやみにvectorなんて使うんじゃない
多分そういうことだと思います

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int h, res;
int isp[1000002];
int hpr[1000002];
int co[1000002];
int dp[1000002];
int main() {
    fill(isp, isp+1000002, 1);
    isp[0]=isp[1]=0;
    int pos=0;
    for (int i=5; i<1000002; i+=4) {
        if (isp[i]) {
            hpr[pos++]=i;
            for (int j=i*2; j<1000002; j+=i) isp[j]=0;
        }
    }
    for (int i=0; i<pos; i++) {
        for (int j=0; j<=i; j++) {
            if (hpr[i]*hpr[j]>1000002) break;
            co[hpr[i]*hpr[j]]=1;
        }
    }
    for (int i=0; i<1000001; i++) {
        dp[i+1]=dp[i]+co[i+1];
    }
    while (scanf("%d",&h)) {
        if (!h) break;
        printf("%d %d\n",h,dp[h]);
    }
}

終わった