`
jishublog
  • 浏览: 866485 次
文章分类
社区版块
存档分类
最新评论

Codeforces Round #200 (Div. 2) 水题4道~

 
阅读更多

今晚是第200场,在div2水了几题水题。。。

第三题始终找不到思路,还是赛后做的。。。

嘛,这次总算是做出了三题,还没被hack,感觉还不错,不过这次实在太水了,rating没降实在不错~

姑且贴下代码吧~

A - Magnets

题意:01和10代表一个磁铁的两种摆法,1,0表示正负极,同性相斥异性相吸,问排成一排后会变成几组磁铁。

简单模拟。。。

代码:

/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        A.cpp
*  Create Date: 2013-09-14 23:29:09
*  Descripton:  simulate 
*/

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
	int n, t, tt, sum = 1;
	cin >> n;
	cin >> t;
	rep(i, n - 1) {
		cin >> tt;
		if (tt == t)
			continue;
		else {
			t = tt;
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


B - Simple Molecules

有关化学的背景。。。谷歌翻译了看了好久,最后还是去看原文了。。。

题意:三个原子构成一个分子,原子键的连接规则是一定得全部原子都联通,且不能自己连自己。给出三个原子各连出了几条键,原子间的连键情况。

画下图找下规律就出来了。。。我也说不清怎么推出了,看代码。

代码:

/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        B.cpp
*  Create Date: 2013-09-14 23:50:09
*  Descripton:  greedy 
*/

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
	int a, b, c, sum, M, r[3];
	cin >> a >> b >> c;
	sum = a + b + c;
	M = max(a, max(b, c));
	if (sum - M >= M && ((sum - M) - M) % 2 == 0) {
		int ta = ((sum - M) - M) / 2;
		if (a >= b && a >= c) {
			r[1] = ta;
			r[0] = b - ta;
			r[2] = c - ta;
		}
		else if (b >= a && b >= c) {
			r[2] = ta;
			r[0] = a - ta;
			r[1] = c - ta;
		}
		else {
			r[0] = ta;
			r[1] = b - ta;
			r[2] = a - ta;
		}
		printf("%d %d %d\n", r[0], r[1], r[2]);
	}
	else printf("Impossible\n");
	return 0;
} 


C - Rational Resistance

题意:电阻可以串联并联,然后给出目标电阻a/b,求最少需要几个电阻才能达到目标电阻。

模拟gcd即可,比赛时没想出来,orz各位大神~

代码:

/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        C.cpp
*  Create Date: 2013-09-15 10:26:31
*  Descripton:  simulate 
*/

#include <iostream>
using namespace std;

int main() {
	long long a, b, t, cnt = 0;
	cin >> a >> b;
	while (b) {
		cnt += a / b;
		t = a % b;
		a = b;
		b = t;
	}
	cout << cnt << endl;
	return 0;
}


D - Alternating Current

比赛时cf由于太卡了,比赛延长了10分钟。

我做到第三题时卡住了,没有思路,于是准备放弃治疗了,去洗了趟澡回来后发现大家都说D太水,于是我稍微看了一下,5分钟敲完过掉了 = =。。。

题意:如题目中图所示,+-线相缠绕,给出每个交叉点在上面是哪条线,问这俩线能不能拉成平行的线。(大概就是这样- -)

在草稿纸上画了一下,发现只有连续的偶数个相同的交叉点才能消掉,如果遍历模拟消掉怕会超时,于是想到了栈,每次把+-放进去时判断和栈顶元素是不是一样,一样就把栈顶弹出,不一样就压入,这样就能保证栈里面肯定没有连续相同的元素,且消掉时是成对消除的,跟括号匹配一样。。。

代码:

/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        D.cpp
*  Create Date: 2013-09-15 01:30:30
*  Descripton:  CF200.2 D
*/

#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;

char ch;

int main() {
	stack<char> s;
	while (scanf("%c", &ch) != EOF && ch != '\n') {
		if (s.empty())
			s.push(ch);
		else {
			char t = s.top();
			if (t == ch)
				s.pop();
			else
				s.push(ch);
		}
	}
	if (s.size())
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}


分享到:
评论

相关推荐

    Codeforces Round #723 (Div. 2).md

    Codeforces Round #723 (Div. 2).md

    Codeforces Round #630 (Div. 2) D. Walk on Matrix(构造)

    上面代码跑出来的dp[n][m]是0,然后从(1,1)(1,2)(2,2)(2,3)这样的相与值是k (看懂ans+k是啥应该就懂了) 代码: int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int ans=(1&...

    Codeforces Round #627 (Div. 3) C. Frog Jumps(思维)

    传送门 题意: 开始位置在0,问能否跳到n+1位置 每步只能跳d 在1——n每个位置有方向,L,R,求d的最小值 思路: 只用找相邻两个R之间的最大值即可 代码: #include #include ...typedef long long l

    Codeforces Round #627 (Div. 3) B. Yet Another Palindrome Problem

    就是把所有相等的数放到一个vector里,如果他出现大于2次,看最远的间距是否大于2即可,找到一个就可以 代码: #include #include #include #include #include #include #include #include #include #include #...

    Codeforces Round #629 (Div. 3) B. K-th Beautiful String

    长度为n的字符串包含n−2n−2n−2个aaa和222个bbb,求按照字典序排列输出第kkk个字符串 解题思路 第一个bbb在倒数第二位有1个字符串,在倒数第三位有2个字符串…在倒数第nnn位时有n−1n-1n−1个字符串 可以根据第一...

    Codeforces Round #479 (Div. 3) E. Cyclic Components

    E. Cyclic Components 题目链接-E. Cyclic Components 题目大意 给你nnn个点和mmm条边,求所构成图中单圈环的个数 ...并查集并查集并查集 很明显单圈环每个点的度都为222,所以我们可以用数组cnt[]记录每个点的度,...

    Codeforces Round #629 (Div. 3) E.Tree Queries (DFS)

    Codeforces Round #629 (Div. 3) E.Tree Queries (DFS) 思路:若ai 在路径上 ,则ai的父结点一定在路径上,若ai是路径上某个结点的子结点,则ai的父结点一定在路径上,综上只需考虑ai的父节点就行了。对每个ai判断...

    Codeforces Round #628 (Div. 2) A~~D

    A #include using namespace std; typedef long long ll; int main(){ int t; cin&gt;&gt;t; while(t--){ ll x; cin&gt;&gt;x; cout&lt;&lt;1&gt;&gt;t; while(t--){ st.clear(); ll n; cin &gt;&gt;n;... ll re

    Codeforces Round #628 (Div. 2)

    给两两节点放一个数字(0~n-2 唯一) 给你一棵树,求所有任意两节点相连的路以外的路上的数字的最小值最小 思路 构造 若一个点连了三条边及以上,则这个点的边从最小值开始赋值。其他边从最大点开始赋值。 证明:一...

    Codeforces Round #620 (Div. 2) Longest Palindrome

    B. Longest Palindrome time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Returning back to problem solving, Gildong is now studying about ...

    Codeforces Round #635 (Div. 2)D. Xenia and Colorful Gems

    其实这道题比较水,但当时思路错,一心想着化简公式,浪费了好多时间a.a 题意:三个数组,求(x-y)(x-y)+(x-z)(x-z)+(y-z)*(y-z)的最小值 题解:6nlogn,先sort三个数组a,b,c, 六次枚举二分查找,再每次min找最小值,...

    Codeforces Round #628 (Div. 2) A. EhAb AnD gCd

    输入一个正整数x,找出这样的2个正整数a和b,使得gcd(a,b)+lcm(a,b)=x 解题思路 找最特殊的情况a=1,b=x-1即可 这样a,b两个数最大公因数为1,最小公倍数x-1,满足题意√ 附上代码 #include #define int long long #...

    Educational Codeforces Round 83 (Rated for Div. 2) D

    C(n-2,i-1)*C(j-1,n-2)*(i-1) __ j: n-1 -&gt; m 我们发现内层循环,每次只是j加一,我们就可以只用一次组合数剩下的用差量表示 对于外层循环同理 只有(i-1) * C(n-2,i-1) i会每次加一。我们也只算一次剩下的用差量...

    Codeforces Round #627 (Div. 3) A. Yet Another Tetris Problem

    给一个长度为n的数组,两种操作,一个是把任意一个ai变成ai+2a_i变成a_i+2ai​变成ai​+2,另一个是如果所有数都大于0,可以把所有数减1,问通过这些操作能否把所有数变为0 思路: 如果任意两个数之差为奇数,那么就...

    Codeforces Round #633 (Div. 2) A. Filling Diamonds(找规律)

    传送门 题意: 找规律,题意就是有多少种方式填充该图形 画两个就发现,输出n即可 代码: #include #include #include #include #include #include #include #include ...#define SZ(x) ((int)(x)

    Codeforces Round #628 (Div. 2)【A B C D】

    传送门 A. EhAb AnD gCd 直接输出1,n-1即可 #include #include #include #include #include #include #include #include #include #include #define pb push_back #define lb lower_bound ...con

    【Codeforces Round#620 (Div. 2)】B. Longest Palindrome 题解

    题目链接:B. Longest Palindrome 题目 Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse....

    Codeforces Round #633 (Div. 2) B. Sorted Adjacent Differences(排序,思维)

    -2,4,5,5,6,8 要输出的序列应该是每次从前面选一个,然后从后面选一个 -2,8,4,6,5,5 然后把该序列倒着输出即可 代码: #include #include #include #include #include #include #include #include #...

    Codeforces Round #618 (Div. 2) C. Anu Has a Function(进制,位运算,贪心)

    将所有数字看成2进制,从最高位看起,如果第i位上为1的数只有一个的话,那么这个数必然对答案有贡献,就把它排在第一个,后面任意排。 例:11,6,4,0 二进制表示为:1011,110,100,0 右起第四位为1的只有1011,...

Global site tag (gtag.js) - Google Analytics