[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 ...
随机推荐
- vs2008 打开项目 无法读取项目文件
卸载vs2015之后 出现问题 C:\Windows\SysWOW64\regedit.exe 64系统运行这个 删除 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MS ...
- sql 排序
select count(*) from vote group by contents PERCENT * from vote order by contents)as A group by cont ...
- 利用node、express初始化项目
前端做整站是开发,例如:前端是用了vue创建初始化项目,后端我们不会php.java等,我们只能用node去创建去做后端代码,本文就给大家讲解最基础的从零开始创建一个项目的后端环境. 一般来说前后端代 ...
- 7.5 pragma 指令
第1个pragma禁用了我们感兴趣的特别警告,第2个恢复了它.禁用尽可能小的一段代码的警告是一个良好的做法,以便你不会错过任何真正应该修复的错误.如果你想在单独一行上禁用或恢复多个警告,那么只需用逗号 ...
- 写代码怎能不会这些Linux命令?
转自:https://zhuanlan.zhihu.com/p/28674639?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=to ...
- 使用Linux自带的命令logrotate对Nginx日志进行切割
说明: Nginx安装目录:/usr/local/nginx/Nginx日志目录:/var/log/nginx/error/*.log /var/log/nginx/access/w1/*.log / ...
- 亚马逊免费服务器搭建Discuz!论坛过程(一)
1:申请 目前亚马逊服务器免费12个月,需要一张信用卡即可免费注册领取. 地址:https://aws.amazon.com/cn/free/ 2: 创建实例 2.1进入控制台:https://ap- ...
- Java并发之CAS与AQS简介
1,什么是CAS CAS(Compare And Swap),即比较并交换.是解决多线程并行情况下使用锁造成性能损耗的一种机制,CAS操作包含三个操作数——内存位置(V).预期原值(A)和新值(B). ...
- CF789B. Masha and geometric depression
/* CF789B. Masha and geometric depression http://codeforces.com/contest/789/problem/B 水题 各种特判,贼烦 */ ...
- I - Tunnel Warfare
I - Tunnel Warfare HDU - 1540 思路:原来以为自己已经完全理解了线段树,现在发现其实还差一些火候,做题的时候太拘泥于格式,思路不是很能放开. #include<cst ...