这套题是昨天晚上做的,也就是从昨天开始刷CF。
先说一下我的计划:
从Round400开始刷CF,div1,2,3都要做,并记录自己的刷题进度,限时刷题(像比赛一样)+ 补题。
以此记录我的CF变红?变紫?之路。
题目链接: http://codeforces.com/contest/776
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
有关质因子的规律题,很明显,顶多是1,2然后质数是1非质数是2就行了比较简单。
#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感觉题目思维量很大,需要大量练习才行。加油~