Codeforces Round #282 (Div2)
2014-12-15 01:02
405 查看
A - Digital Counter(纯模拟)
B - Modular Equations
记录o(sqrt(n))的因数搜索方法。【原来好像写过类似的,比赛的时候却一点也记不得了。。】
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;
}
#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;
}
相关文章推荐
- Codeforces Round #282 (Div. 1) A. Treasure (贪心)
- Codeforces Round #282 (Div. 2) A - Digital Counter B - Modular Equations C - Treasure
- **Codeforces Round #282 (Div. 2) C. Treasure ACM解题报告(构造难题)
- Codeforces Round #282 (Div. 2) A.(乘法原理)
- Codeforces Round #282 (Div. 2) C. Treasure 贪心
- Codeforces Round #282 (Div. 1) B. Obsessive String
- Codeforces Round #282 (Div. 2) c
- Codeforces Round #282 (Div. 2) B. Modular Equations&C. Treasure
- Codeforces Round #282 Div.1 B Obsessive String --DP
- Codeforces Round #282 (Div. 2)---A. Digital Counter
- Codeforces Round #272 (Div. 2) D
- Codeforces Round #420 (Div. 2) 821
- Codeforces Round #420 (Div. 2) 题解
- 【Codeforces Round #170 Div. 1】 227A Learning Languages
- Codeforces Round #244 (Div. 2) A~C
- Codeforces Round #244 (Div. 2) B. Prison Transfer
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out!+二叉树
- Codeforces Round #211 (Div. 2)
- Codeforces Round #211 (Div. 2) D题Renting Bikes
- Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army RMQ问题 ST算法