Codeforces Round #478 Div2 975A 975B 975C 975D

A. Aramic script

题目大意:

\ 对于每个单词,定义一种集合,这个集合包含且仅包含单词中出现的字母。给你一堆单词,问有多少种这种集合。

题解:

\ 状压,插入set,取size

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <set>
#include <cmath>
inline int max(int a, int b){return a > b ? a : b;}
inline int min(int a, int b){return a < b ? a : b;}
inline int abs(int x){return x < 0 ? -x : x;}
inline void swap(int &x, int &y){int tmp = x;x = y;y = tmp;}
inline void read(int &x)
{
	x = 0;char ch = getchar(), c = ch;
	while(ch < '0' || ch > '9') c = ch, ch = getchar();
	while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
	if(c == '-') x = -x;
}
const int INF = 0x3f3f3f3f;

int n, cnt;
char s[1010];
std::set<int> st;

int main()
{
	read(n);
	for(int i = 1;i <= n;++ i)
	{
		scanf("%s", s + 1), cnt = 0;
		for(int j = 1;s[j] != '\0';++ j) 
			cnt |= (1 << (s[j] - 'a'));
		st.insert(cnt);
	}
	printf("%d", st.size());
	return 0;
}

B. Mancala

题目大意:

\ 14个孔,孔里有一些小球。选择一个孔i,拿出里面所有球,一个一个依次往i,(i+1),(i+2)。。。。到14后,再从1,2,3,........无限循环下去,直到拿出来的求被放回去。14个孔里,个数为偶数的个数和就是分值。问最大分值。

题解:

\ 枚举哪个空,%14后的求暴力模拟,然后求答案。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a < b ? a : b;}
inline long long abs(long long x){return x < 0 ? -x : x;}
inline void swap(long long &x, long long &y){long long tmp = x;x = y;y = tmp;}
inline void read(long long &x)
{
	x = 0;char ch = getchar(), c = ch;
	while(ch < '0' || ch > '9') c = ch, ch = getchar();
	while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
	if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f;

long long num[20], tmp[20], tot, ans, cnt;

int main()
{
	for(long long i = 1;i <= 14;++ i) read(num[i]);
	for(long long i = 1;i <= 14;++ i)
	{
		tot = cnt = 0;
		for(long long j = 1;j <= 14;++ j) tmp[j] = num[j];
		tot += tmp[i] / 14, tmp[i] %= 14;
		for(long long j = i + 1;j <= 14 && tmp[i];++ j) -- tmp[i], ++ tmp[j];
		for(long long j = 1;j < i && tmp[i];++ j) -- tmp[i], ++ tmp[j];
		for(long long j = 1;j <= 14;++ j)
			if((tot + tmp[j]) % 2 == 0)
				cnt += tot + tmp[j];
		ans = max(ans, cnt);
	}
	printf("%I64d", ans);
	return 0;
}

C. Valhalla Siege

题目大意:

\ \(n\)个士兵排成一列,每个士兵有血量\(a_i\)\(q\)分钟,每分钟对士兵造成共计\(k_i\)点伤害。即若第一个士兵血量归零,当前分钟剩余伤害则给第二个士兵,以此类推。当士兵全部死亡时,剩余的伤害会全部落空,而后士兵会全部复活。问每一分钟伤害造成后剩余多少士兵。

题解:

\ 求\(a\)的前缀和,二分模拟即可。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a < b ? a : b;}
inline long long abs(long long x){return x < 0 ? -x : x;}
inline void swap(long long &x, long long &y){long long tmp = x;x = y;y = tmp;}
inline void read(long long &x)
{
	x = 0;char ch = getchar(), c = ch;
	while(ch < '0' || ch > '9') c = ch, ch = getchar();
	while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
	if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f;

long long n, q, a[200010], k[200010], tot, p;

int main()
{
	read(n), read(q);
	for(long long i = 1;i <= n;++ i) read(a[i]), a[i] += a[i - 1];
	for(long long i = 1;i <= q;++ i) 
	{
		read(k[i]);
		p = std::lower_bound(a + 1, a + 1 + n, tot + k[i]) - a;
		if(a[p] != tot + k[i]) -- p;
		if(p >= n) printf("%I64d\n", n), tot = 0;
		else printf("%I64d\n", n - p), tot += k[i]; 
	}
	
	return 0;
}

D. Ghosts

题目大意

\ 给定一条直线\(y=ax+b\),直线上有一些点,每个点都有运动速度,运动时间无限,问有多少点能相遇。

题解

\ 对于任意两个点\((x_1, y_1),(, x_2, y_2)\),时间为\(t\),若他们速度分别为\((v_{x1}, v_{y1}), (v_{x2}, v_{y2})\),速度完全相等时不可能相交,不完全相等时,若能相交,则有:

\[x_1 + v_{x_1}t = x_2 + v_{x_2}t \]

\[y_1 + v_{y_1}t = y_2 + v_{y_2}t \]

联立可得:

\[\frac{x_1 - x_2}{v_{x_2} - v_{x_1}} = \frac{y_1 - y_2}{v_{y_2} - v_{y_1}}$$ ① 两点式: $$y_1 - y_2 = a(x_1 - x_2)$$ ② 联立①②,有: $$v_{y_1} - av_{x_1}=v_{y_2}-ax_{x_2}\]

于是只需统计满足上式的对数,减去速度完全相等的点的对数(速度完全相等的点显然也满足上式),即为答案。
用两个map记录。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map> 
#include <cmath>
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a < b ? a : b;}
inline long long abs(long long x){return x < 0 ? -x : x;}
inline void swap(long long &x, long long &y){long long tmp = x;x = y;y = tmp;}
inline void read(long long &x)
{
	x = 0;char ch = getchar(), c = ch;
	while(ch < '0' || ch > '9') c = ch, ch = getchar();
	while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
	if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f;
std::map<std::pair<long long, long long>, long long> mp2;
std::map<long long, long long> mp1;
long long n, a, b, x, vx, vy, ans, tmp;
int main()
{
	read(n), read(a), read(b);
	for(long long i = 1;i <= n;++ i)
	{
		read(x), read(vx), read(vy);
		ans += mp1[vy - a * vx]; 
		++ mp1[vy - a * vx];
		ans -= mp2[std::make_pair(vx, vy)];
		++ mp2[std::make_pair(vx, vy)];
	}
	printf("%I64d", ans << 1);
	return 0;
}
posted @ 2018-05-10 10:15  嘒彼小星  阅读(270)  评论(0编辑  收藏  举报