Codeforces Round #282 (Div. 2)

也是几百年没做CF咯,这场还是赛后做的,退化很多啦

A.Digital Counter

找规律 可能有火柴棍丢失,问你可能组成的数字有多少种,只需要肉眼看看每个数字填上火柴棍可能形成的数字,打个表就行了

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

const int pos[] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};

int a, b;

int main()
{
#ifdef LOCAL
    freopen("495A.in", "r", stdin);
#endif
    a = getchar() - ‘0‘;
    b = getchar() - ‘0‘;
    printf("%d\n", pos[a]*pos[b]);
    return 0;
}

B. Modular Equations

一开始没读懂题意,还以为是同余...就是

a / x = y ... b  给你a,b让你求x的可能个数

因为b是余数,所以需要满足0<=b<x

和素数只需要检查到sqrt(x)差不多,这里只需要枚举到sqrt(a-b)

这个复杂度还是能接受的O(sqrt(a-b))

一开始很傻逼,从sqrt(a-b)枚举到a-b...瞬间爆炸...TLE

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

const int MAXN = 1e5;
int a, b, cnt;
int pcnt[MAXN];
bool prime[MAXN];

int main()
{
#ifdef LOCAL
    freopen("495B.in", "r", stdin);
#endif
    scanf("%d%d", &a, &b);
    if(a < b)    printf("0\n");
    else if(a == b)    printf("infinity\n");
    else {
        a -= b;
        for(int i = 1, t = sqrt(a); i <= t; i++) {
            if(a % i)    continue;
            int x = i, y = a/i;
            if(x > b)    cnt++;
            if(y > b)    cnt++;
            if(x > b && x == y)    cnt--;
        }
        printf("%d\n", cnt);
     }
    return 0;
}

C. Treasure

感觉就是贪心了...一开始想法傻逼了,还去细分讨论很多,把自己绕进去了

就是让前面的‘#‘填入1个‘)‘,最后一个填入剩下所需的‘)‘

再跑一边检查一下有没有那个位置会使得‘)‘个数多余‘(‘个数

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;

const int MAXN = 1e5+10;

int mcnt, acnt, hpos, lpos, lh;
int	inf[MAXN];
char ins[MAXN];
bool possible = true;
queue<int> h;

void noAnswer()
{
	printf("-1\n");
	exit(0);
}

int main()
{
#ifdef LOCAL
	freopen("495C.in", "r", stdin);
#endif
	scanf("%s", ins);
	for(int i = 0, t = strlen(ins); i < t; i++) {
		if(ins[i] == ‘(‘)	mcnt++;
		else if(ins[i] == ‘)‘)	mcnt--;
		else {
			lh = i;
			mcnt--;
			inf[i] = 1;
			h.push(i);
		}
	}
	if(mcnt < 0)	noAnswer();
	inf[lh] += mcnt;
	mcnt = 0;
	for(int i = 0, t = strlen(ins); i < t; i++) {
		if(ins[i] == ‘(‘)	mcnt++;
		else if(ins[i] == ‘)‘)	mcnt--;
		else mcnt -= inf[i];
		if(mcnt < 0)	noAnswer();
	}
	while(!h.empty()) {
		printf("%d\n", inf[h.front()]);
		h.pop();
	}
	return 0;
}

 

D.Obsessive String

感觉CF的D题是足以制裁我了呢...KMP早就忘光了 更别说还要DP了 有空写写吧~

  ABC做下来感觉细节还是蛮多的,不知道是因为自己退化了,还是这次比赛偏细节

时间: 2024-08-05 02:37:20

Codeforces Round #282 (Div. 2)的相关文章

Codeforces Round #282 (Div. 2) a

/**  * @brief Codeforces Round #282 (Div. 2) a  * @file a.cpp  * @author mianma  * @created 2014/12/15 9:55  * @edited  2014/12/15 9:55  * @type math  * @note  */ #include <fstream> #include <iostream> #include <cstring> using namespace 

Codeforces Round #282 (Div. 2) c

/**  * @brief Codeforces Round #282 (Div. 2) c  * @file c.cpp  * @author mianma  * @created 2014/12/16 16:09  * @edited  2014/12/16 16:09  * @type math  * @note  */ #include <fstream> #include <iostream> #include <cstring> #include <c

数学 Codeforces Round #282 (Div. 2) B. Modular Equations

题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1,那么24,12, 8, 6, 4, 3, 2都可以,所以只要求出k的约数有几个就可以了,a <= b的情况要特判 /************************************************* Author        :Running_Time* Created Time  

Codeforces Round #282 (Div. 2) b

/**  * @brief Codeforces Round #282 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/12/15 9:55  * @edited  2014/12/15 9:55  * @type math  * @note  */ #include <fstream> #include <iostream> #include <cstring> #include <cma

Codeforces Round #282 (Div.1) Solution

上午考试,下去去参观教堂,回来睡大觉,搞到现在才有时间做,水平恢复中. A 倒过来扫括号匹配很容易理解 B dp[i]表示最后一个拿到i的数目,sum[i]表示前i项dp和,sum2[i]表示前i项sum和.显然.dp[i]=sum2[o], o是最右边的坐标使得s[o+1,i]能包含t. C Interesting,我建了个树,硬着dp搞得..还没优化就46ms,想来这种题数据也不好构造. D Editorial似乎说离线搞,不过我在线搞出来了.我存了每个节点子树平方和,子树和,整体和,整体平

Codeforces Round #282 Div.1 B Obsessive String --DP

题意: 给两个串S,T,问能找出多少的S的(a1,b1)(a2,b2)..(ak,bk),使Sa1---Sb1,...Sak---Sbk都包含子串T,其中k>=1,且(a1,b1)...(ak,bk)互不相交. 比如S = "abacaba",T="aba", 当k=1时,(0,6)满足,还有其他只包含一个aba串的也满足,k-2时,(0,2)(3,6)满足,(0,2)(4,6)也满足,(0,3)(4,6)也满足,所以总共有12种. 解法:dp.先用kmp找出

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿