CF 474D Flowers

/* 7/14/2018
* Problem: http://codeforces.com/problemset/problem/474/D
* Solution: Dp. dp[i] = dp[i-1] + dp[i-k]. One state can be transferred to from two sources: 1. eat only white flower from the i-k day 2. otherwise.
* Notes: 1. Remember to mod the MOD every time there’s a summing process.
2. The result of a mod can be negative.
* A little bit gibber-gabber:
For both the notes, I KNEW it but I now don’t..??
What is the point of everything..
*/

#include
using namespace std;

int main() {
	int t, k;
	cin >> t >> k;
	long long ind[100005] = {0}, sum[100005] = {0};
	int MOD = 1000000007;
	for (int i = 0; i < k; i++) {
		ind[i] = 1;
	}
	for (int i = k; i <= 100005; i++) {
		ind[i] = (ind[i - 1] + ind[i - k]) % MOD;
	}
	sum[0] = 1;
	for (int i = 0; i  a >> b;
		long long ans = (sum[b] - sum[a - 1]) % MOD;
		if (ans < 0) {
			ans += MOD;
		}
		cout << ans << endl;
	}
	return 0;
}


2017 PacNW C Fear factoring

/* 11/12/2017
*/


#include
#include 
using namespace std;

int main() {
	long long a,b;
	cin >> a >> b;
	long long tmp = sqrt(b);
	long long ans = 0;
	for (long long i = 1; i <= tmp; i++) {
		long long lb = max(tmp, (a-1) / i) + 1;
		long long ub = max(tmp, b / i);
		ans += i * (b / i - (a-1)/ i) + (lb + ub) * (ub - lb + 1) / 2;
	}
	cout << ans;
	return 0;
}

2017 PacNW E Straight Shot

/* 11/16/2017
* Solution: Use binary search to find the appropriate angle.
*/

#include
#include
#include
#define PI acos(-1)
using namespace std;

int main() {
	long long n, x;
	double vv;
	int ll, rr;
	double v;
	double summ = 0;
	cin >> n >> x >> v;
	for (int i = 1; i > ll >> rr >> vv;
		summ += (rr - ll) * 1.0 * vv / v;
	}
	if (summ > 0) {
		summ = - summ;
	}
	double l = 0, r = 90;
	double result = 100; 
	while (abs(result) > 1e-5) {
		if (l > 60) {
			cout  60) {
		cout << "Too hard";
	} else {
		cout << fixed << setprecision(3) << (double)x / (v * cos(l * PI / 180));
	}
	return 0;
} 

CF 977E Cyclic Components

Date: 5/8/2018
Problem: http://codeforces.com/problemset/problem/977/E
Solution: According to the definition, if several vertices are a cycle, all the vertices must have a degree of two. So, check only the vertices that has a degree of two, and see how many are circles can be constructed.


#include
#include
using namespace std;

int deg[200005] = {0};
bool vst[200005];
vector e[200005];
vector cycle;

void dfs(int i) {
	vst[i] = true;
	cycle.push_back(i);
	for (vector::iterator it = e[i].begin(); it != e[i].end(); ++it) {
		if (!vst[*it]) {
			dfs(*it);
		}
	}
}

int main() {
	int n, m;
	int ans = 0;
	cin >> n >> m;
	for (int i = 1; i > a >> b;
		deg[a]++;
		deg[b]++;
		e[a].push_back(b);
		e[b].push_back(a);
	}	
	for (int i = 1; i <= n; i++) {
		if (!vst[i]) {
			cycle.clear();
			vst[i] = true;
			dfs(i);
			bool b = true;
			for (vector::iterator it = cycle.begin(); it != cycle.end(); ++it) {
				if (deg[*it] != 2) {
					b = false;
					break;
				}
			}
			if (b) {
				ans++;
			}
		}
	}
	cout << ans;
	return 0;
}