您的位置:首页 > 其它

Codeforces Round #282 (Div2)

2014-12-15 01:02 405 查看
A - Digital Counter(纯模拟)

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;

const int d[10][7] = {
{1, 1, 1, 0, 1, 1, 1},
{0, 0, 1, 0, 0, 1, 0},
{1, 0, 1, 1, 1, 0, 1},
{1, 0, 1, 1, 0, 1, 1},
{0, 1, 1, 1, 0, 1, 0},
{1, 1, 0, 1, 0, 1, 1},
{1, 1, 0, 1, 1, 1, 1},
{1, 0, 1, 0, 0, 1, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1}
};

bool checkBig(int a, int b)
{
for(int i = 0; i < 7; i++)
if(d[a][i] < d[b][i])
return false;
return true;
}

int s, g, ns, ng;

int main()
{
//    freopen("A.in", "r", stdin);

int x;
scanf("%d", &x);
s = x / 10, g = x % 10;

ns = ng = 0;
for(int i = 0; i < 10; i++)
{
if(checkBig(i, s)) ns++;
if(checkBig(i, g)) ng++;
}

printf("%d\n", ns * ng);

return 0;
}


B - Modular Equations

记录o(sqrt(n))的因数搜索方法。【原来好像写过类似的,比赛的时候却一点也记不得了。。】

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;

int a, b;

int main()
{
scanf("%d%d", &a, &b);
if(a < b)
{
printf("0\n");
return 0;
}
if(a == b)
{
printf("infinity\n");
return 0;
}
a -= b;
int t = sqrt(a) + 1;
if(t * t > a) t--;
int ans = 0;
for(int i = 1; i <= t; i++)
{
if(a % i == 0)
{
if(i > b) ans++;
if((a / i) > b && (i * i != a)) ans++;
}
}
printf("%d\n", ans);

return 0;
}


C - Treasure

每一个在一起的左右括弧直接匹配。再对每一个井号都先匹配它前面的第一个左括弧,这样到了最后一个井号的时候它的左边就只剩下左括弧了。然后检查井号后面的括弧能不能匹配。

#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
#define MAXN 100010
#define OT(x) printf("%d\n", x);
#define CLR(x, a) memset(a, x, sizeof(a));
#define REP(i, n) for(i = 0; i < (n); i++)
#define FOR(i, s, e) for(i = (s); i < (e); i++)
#define DWN(i, s, e) for(i = (e) - 1; i >= (s); i--)

char s[MAXN];
int ans[MAXN];
int len, w, i, p, cnt, tot;

bool ck(void)
{
p = len = strlen(s);
tot = cnt = w = 0;
if(s[0] == ')' || s[0] == '#' || s[len - 1] == '(') return false;
REP(i, len)
{
if(s[i] == '(') tot++;
if(s[i] == ')') tot--;
if(s[i] == '#') w++, p = i;
if(tot < 0 || w > tot) return false;
}
cnt = 0;
DWN(i, p + 1, len)
{
if(s[i] == ')') cnt++;
if(s[i] == '(') cnt--;
if(cnt < 0) return false;
}
return true;
}

int main()
{
// freopen("C.in", "r", stdin);

gets(s);
if(ck()) { REP(i, w - 1) OT(1); OT(tot - w + 1); }
else OT(-1)
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: