这里直接贴我的程序,题目和思路另翻博客
B. Sherlock and his girlfriend`//
// main.cpp
// journey
//
// Created by zhangdenny on 2017/3/4.
// Copyright © 2017年 Kirito. All rights reserved.
//
#include <functional>
#include <algorithm>
#include <exception>
#include <stdexcept>
#include <streambuf>
#include <iterator>
#include <string.h>
#include <stdlib.h>
#include <typeinfo>
#include <valarray>
#include <iostream>
#include <sstream>
#include <istream>
#include <stdio.h>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <ctype.h>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <cstring>
#include <numeric>
#include <ostream>
#include <cwctype>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <limits>
#include <locale>
#include <memory>
#include <cerrno>
#include <iosfwd>
#include <cfloat>
#include <cstdio>
#include <cwchar>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <ios>
#include <map>
#include <set>
#include <new>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
int n,m,t;
int main()
{
cin>>t;
if(t<=2)
cout<<"1"<<endl;
else
cout<<"2"<<endl;
int j;
for(int i=2;i<=t+1;i++)
{
m=sqrt(i);
for(j=2;j<=m;j++)
if(i%j==0)
break;
if(j>m)
cout<<"1 ";
else cout<<"2 ";
}
return 0;
}`
C. Molly’s Chemicals
//
// main.cpp
// journey
//
// Created by zhangdenny on 2017/3/4.
// Copyright © 2017年 Kirito. All rights reserved.
//
#include <functional>
#include <algorithm>
#include <exception>
#include <stdexcept>
#include <streambuf>
#include <iterator>
#include <string.h>
#include <stdlib.h>
#include <typeinfo>
#include <valarray>
#include <iostream>
#include <sstream>
#include <istream>
#include <stdio.h>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <ctype.h>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <cstring>
#include <numeric>
#include <ostream>
#include <cwctype>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <limits>
#include <locale>
#include <memory>
#include <cerrno>
#include <iosfwd>
#include <cfloat>
#include <cstdio>
#include <cwchar>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <ios>
#include <map>
#include <set>
#include <new>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
ll n,k,dq;
vector<ll> v;
ll x;
map<ll,int> mp;
ll ans;
int main()
{
cin>>n>>k;
dq=1;
mp.clear();
if (abs(k)==1)
{
v.push_back(1);
if (k==-1) v.push_back(-1);
}
else
{
while (dq<=1e14)
{
v.push_back(dq);
dq=dq*k;
}
}
mp[0]=1;
dq=0;
for (int i=1;i<=n;++i)
{
cin>>x;dq+=x;
for (int j=0;j<v.size();j++)
if (mp.count(dq-v[j])!=0)
ans+=mp[dq-v[j]];
mp[dq]+=1;
}
cout<<ans<<endl;
return 0;
}
伸手党走开