[Codeforces]Good Bye 2017
A - New Year and Counting Cards
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int a[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
string s;
cin >> s;
int n = s.size();
for (int i = ; i < n; i++) a[s[i]]++;
cout << (a[''] + a[''] + a[''] + a[''] + a[''] + a['a'] + a['e'] + a['i'] + a['o'] + a['u']) << endl;
return ;
}
B - New Year and Buggy Bot
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} string mp[], s;
int d[], op[];
const int dx[] = {-, , , };
const int dy[] = {, , , -}; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, m;
cin >> n >> m;
for (int i = ; i < n; i++) cin >> mp[i];
cin >> s;
int l = s.size();
for (int i = ; i < l; i++) op[i] = s[i] - '';
int sx, sy;
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++) {
if (mp[i][j] == 'S') {
sx = i;
sy = j;
}
}
}
int ans = ;
bool f[];
for (d[] = ; d[] < ; d[]++) {
for (d[] = ; d[] < ; d[]++) {
for (d[] = ; d[] < ; d[]++) {
for (d[] = ; d[] < ; d[]++) {
memset(f, false, sizeof(f));
f[d[]] = true, f[d[]] = true, f[d[]] = true, f[d[]] = true;
if (f[] && f[] && f[] && f[]) {
int x = sx, y = sy, j;
bool ok = false;
for (int i = ; i < l; i++) {
j = d[op[i]];
x += dx[j], y += dy[j];
if (x < || x >= n || y < || y >= m) break;
if (mp[x][y] == '#') break;
if (mp[x][y] == 'E') {
ok = true;
break;
}
}
if (ok) ans++;
}
}
}
}
}
cout << ans << endl;
return ;
}
C - New Year and Curling
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} class SAM {
private:
int Last, sz;
vector<int []> ch;
vector<int> fa, maxlen;
public:
void init() {
sz = ;
ch.clear();
}
void add(int x) {
int np = ++sz, p = Last;
Last = np;
memset(ch[np], , sizeof(ch[np]));
maxlen[np] = maxlen[p] + ;
while (p && !ch[p][x]) ch[p][x] = np, p = fa[p];
if (!p) fa[np] = ;
else {
int q = ch[p][x];
if (maxlen[p] + == maxlen[q]) fa[np] = q;
else {
int nq = ++sz;
memcpy(ch[nq], ch[q], sizeof(ch[q]));
maxlen[nq] = maxlen[p] + ;
fa[nq] = fa[q];
fa[q] = fa[np] = nq;
while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];
}
}
}
};
double x[], y[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
//std::ios::sync_with_stdio(0), cin.tie(0);
int n;
double r, h;
//cin >> n >> r;
scanf("%d%lf", &n, &r);
for (int i = ; i < n; i++) {
//cin >> x[i];
scanf("%lf", &x[i]);
y[i] = r;
for (int j = ; j < i; j++) {
if (fabs(x[i] - x[j]) <= * r) {
h = sqrt( * r * r - (x[i] - x[j]) * (x[i] - x[j])) + y[j];
if (y[i] < h) y[i] = h;
}
}
}
for (int i = ; i < n; i++) printf("%.8lf ", y[i]); //cout << y[i] << ' ';
return ;
}
D - New Year and Arbitrary Arrangement
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std; const int MOD = * * + ; ll pw(ll a, ll b = MOD - ) {
if (b == ) {
return ;
} ll v = pw(a, b / );
v = (v * v) % MOD; if (b & ) {
v = (v * a) % MOD;
} return v;
} constexpr int MAXN = ; ll f[MAXN][MAXN]; int main() {
#ifdef PAUNSVOKNO
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(); cout.tie(nullptr); cin.tie(nullptr);
ll k, pa, pb;
cin >> k >> pa >> pb;
ll s = pw(pa + pb);
pa = (pa * s) % MOD;
pb = (pb * s) % MOD; ll ans = ; f[][] = ; ll last = ( - pa + MOD) % MOD;
last = pw(last, MOD - );
last = (last - + MOD) % MOD; for (int i = ; i <= k; ++i) {
for (int j = ; j <= k; ++j) {
if (i + j >= k) {
ll val = j + i + last;
ans = (ans + f[i][j] * val) % MOD;
} else {
f[i + ][j] = (f[i + ][j] + f[i][j] * pa) % MOD;
f[i][j + i] = (f[i][j + i] + f[i][j] * pb) % MOD;
}
}
} cout << ans << "\n";
}
E - New Year and Entity Enumeration
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std; ll m,n,c[][],f[],b[],x,ans=;
map<ll,ll>mp; int main(){
for (cin>>m>>n;n--;)
for (int i=;i<m;++i)
scanf("%1lld",&x), b[i]|=x<<n;
for (int i=;i<m;++i) ++mp[b[i]];
for (int i=;i<=m;++i)
for (int j=;j<=i;++j)
c[i][j]= j? (c[i-][j-]+c[i-][j])%mod: ;
f[]=f[]=;
for (int i=;i<=m;++i)
for (int j=;j<i;++j)
f[i]=(f[i]+c[i-][j]*f[j])%mod;
for (auto o:mp) ans=(ans*f[o.second])%mod;
cout<<ans;
}
F - New Year and Rainbow Roads
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
char ch;
lint pb = , pr = , pg = , mr = , mb = , ans = , x;
cin >> n;
for (int i = ; i < n; i++) {
cin >> x >> ch;
if (ch == 'R' || ch == 'G') {
if (pr) {
ans += x - pr;
mr = max(mr, x - pr);
}
pr = x;
}
if (ch == 'B' || ch == 'G') {
if (pb) {
ans += x - pb;
mb = max(mb, x - pb);
}
pb = x;
}
if (ch == 'G') {
if (pg) ans += min(0LL, x - pg - mr - mb);
pg = x;
mr = mb = ;
}
}
cout << ans << endl;
return ;
}
G - New Year and Original Order
#pragma comment(linker, "/STACK:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<functional>
#include<math.h>
//#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} const int mod = ;
lint dp[][][][];
string s; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
cin >> s;
int n = s.size();
reverse(s.begin(), s.end());
memset(dp, , sizeof(dp));
for (int i = ; i < ; i++) dp[][][i][] = ;
for (int i = ; i < n; i++) {
for (int j = ; j <= i; j++) {
for (int k = ; k < ; k++) {
for (int l = ; l < ; l++) {
for (int p = ; p < ; p++) {
(dp[i + ][j + (p >= k)][k][(s[i] - '' > p) || (l && (s[i] - '' == p))] += dp[i][j][k][l]) %= mod;
}
}
}
}
}
lint ans = ;
for (int i = ; i < ; i++) {
lint t = ;
for (int j = ; j <= n; j++, t = (t * + ) % mod) ans += dp[n][j][i][] * t, ans %= mod;
}
cout << ans << endl;
return ;
}
H - New Year and Boolean Bridges
#include<bits/stdc++.h>
#define N 50
#define fr(i,n) for(int i=1;i<=n;i++)
using namespace std;
int n,i,j,x,S,an,nv,id,to[N],c[N],b[N],F[N],sz[N];bool v[N][N];
char s[N][N];
int gf(int x){return F[x]==x?x:F[x]=gf(F[x]);}
void uni(int x,int y){
x=gf(x);y=gf(y);
if(x!=y)F[x]=y,sz[y]+=sz[x];
}
int main(){
scanf("%d",&n);
fr(i,n)F[i]=i,sz[i]=;
fr(i,n){
scanf("%s",s[i]+);
fr(j,n)if(i!=j)
if(s[i][j]=='A')uni(i,j);
}
fr(i,n)if(gf(i)==i&&sz[i]>)to[i]=++id;
fr(i,n)fr(j,n)if(gf(i)==gf(j)&&s[i][j]=='X')return puts("-1"),;
fr(i,n)fr(j,n)if(s[i][j]=='X')v[to[gf(i)]][to[gf(j)]]=;
fr(i,id)b[i]=i;an=n;
fr(T,){
random_shuffle(b+,b+id+);nv=;
fr(i,id){
x=b[i];S=;
fr(j,id)if(v[x][j])S|=<<c[j];
for(j=;;j++)if(!(S>>j&)){
c[x]=j;
break;
}
nv=max(nv,c[x]);
}
fr(i,id)c[i]=;
an=min(an,nv);
}
printf("%d\n",n-+an);
}
[Codeforces]Good Bye 2017的更多相关文章
- Codeforces Good Bye 2017 908F F. New Year and Rainbow Roads
题 OvO http://codeforces.com/contest/908/problem/F CF 908F 解 需要注意细节的模拟题. 如果三种颜色都存在,则记每两个相邻的G组成一个段,对每个 ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- Good Bye 2017(送命场)
9815人数场,9500+围观神仙打架...断断续续打Codeforces也快有一年啦,第一次打Good Bye场,满怀前排膜tourist的心愿参加了这场送命场,虽然没看到tourist.不过还是得 ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- codeforces Good Bye 2015 B. New Year and Old Property
题目链接:http://codeforces.com/problemset/problem/611/B 题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制 ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
- Codeforces Good Bye 2015 C. New Year and Domino 前缀和
C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
随机推荐
- 01 DOS常用命令
有时候没有可视化窗口,命令行对文件进行操作更方便快捷 cmd 命令弹出 dir 查看当前所在目录下的文件 ctrl+c 退出 \a 显示隐藏文件 cd /改变到根目录 dir /a 显示隐藏文件 di ...
- Python字典 day2
一.字典 1.字典的特点: 一系列键-值对(key-value),字典用放在花括号{ }中的一系列键值对表示; 字典中有多个元素时需要用逗号,隔开: key不能重复: 字典是无序的. 字典的优点:字典 ...
- 第1章 面向对象的JavaScript
针对基础知识的每一个小点,我都写了一些小例子,https://github.com/huyanluanyu1989/DesignPatterns.git,便于大家理解,如有疑问,大家可留言给我,最近工 ...
- UNIX C 文件权限 Part2_day01
1.文件访问测试 测试调用进程对指定文件是否拥有足够的访问权限 #include <unistd.h> int access(const char* pathname,int mode); ...
- 多文件编程(day13)
多文件编程时一个文件里可以包含多个函数, 一个函数只能属于一个文件 多文件编程的步骤 .把所有函数分散在多个不同的源文件里 (主函数通常单独占一个文件) .为每个源文件编写一个配对的以.h作为 扩展名 ...
- Noip 2013 练习
转圈游戏 传送门 Solution 快速幂 Code //By Menteur_Hxy #include <cstdio> #include <cstdlib> #includ ...
- android debug签名文件
现象 可以运行程序,但不能启动安装成功的软件 并且run application的时候也不弹出界面. 路径: C:\Users\sunfb\.android 下替换debug.keystore 就OK
- 痛苦的Windows下的temp目录
2007不能运行了,错误: [MSBuild Error] “DCC”任务意外失败. System.Configuration.ConfigurationErrorsException: 配置系统未能 ...
- Ubuntu14.043下QT5.5的安装与一点问题
请注明来自于 http://www.cnblogs.com/usegear/p/5100720.html 1.下载qt-opensource-linux-x86-5.5.0.run(去教育镜像网站下载 ...
- hdu 2444 交叉染色判断二分图+二分最大匹配
/*1A 31ms*/ #include<stdio.h> #include<string.h> #define N 300 int n; struct node { int ...