codeforces educational round 25
A 出题人不给样例解释。。。具体程序
#include<bits/stdc++.h>
using namespace std;
int n;
char s[];
int main()
{
scanf("%d%s", &n, s + );
int ans = , tot = ;
for(int i = ; i <= n; ++i)
{
if(s[i] == '') ++tot;
else
{
ans = ans * + tot;
tot = ;
}
}
printf("%d\n", ans * + tot);
return ;
}
B 枚举每个点填上黑子,然后判断
#include<bits/stdc++.h>
using namespace std;
const int dx[] = {, , -, -}, dy[] = {, , , };
int n;
char Map[][];
bool check()
{
for(int i = ; i <= ; ++i)
for(int j = ; j <= ; ++j) if(Map[i][j] == 'X')
{
for(int k = ; k < ; ++k)
{
int xx = i, yy = j;
bool flag = true;
for(int l = ; l < ; ++l)
{
xx += dx[k], yy += dy[k];
if(Map[xx][yy] != 'X')
{
flag = false;
break;
}
}
if(flag) return true;
}
}
return false;
}
int main()
{
memset(Map, 'O', sizeof(Map));
for(int i = ; i <= ; ++i)
scanf("%s", Map[i] + );
for(int i = ; i <= ; ++i)
for(int j = ; j <= ; ++j) if(Map[i][j] == '.')
{
char c = Map[i][j];
Map[i][j] = 'X';
if(check())
{
puts("YES");
return ;
}
Map[i][j] = c;
}
puts("NO");
return ;
}
C 贪心,不够就乘2,每次和a取大
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
int n, ans;
ll k;
ll a[N];
int main()
{
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i) scanf("%lld", &a[i]);
sort(a + , a + n + );
for(int i = ; i <= n; ++i)
{
while(k < (a[i] + 1ll) / 2ll)
{
++ans;
k = 2ll * k;
}
if(k >= (a[i] + 1ll) / 2ll) k = max(k, a[i]);
}
printf("%d\n", ans);
return ;
}
D 贪心,能互相交换肯定能换成那个目标串,所以看现在缺少目标串哪个元素就加上
#include<bits/stdc++.h>
using namespace std;
const int N = ;
char s[N], t[N];
int cnt[], cnt1[];
int main()
{
scanf("%s%s", s + , t + );
int len1 = strlen(t + ), len2 = strlen(s + );
for(int i = ; i <= len1; ++i) ++cnt[t[i] - 'a'];
for(int i = ; i <= len2; ++i) if(s[i] != '?')
++cnt1[s[i] - 'a'];
for(int i = ; i <= len2; ++i)
{
bool flag = false;
if(s[i] == '?')
{
int pos = ;
for(int j = ; j < ; ++j) if(cnt1[j] < cnt[j])
{
++cnt1[j];
flag = true;
pos = j;
break;
}
if(!flag)
{
for(int j = ; j < ; ++j) cnt1[j] -= cnt[j];
for(int j = ; j < ; ++j) if(cnt1[j] < cnt[j])
{
++cnt1[j];
pos = j;
break;
}
}
printf("%c", (char)(pos + 'a'));
}
else printf("%c", s[i]);
}
return ;
}
E 贪心,证明待填
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, m;
priority_queue<int> q;
vector<int> G[N];
int c[N], d[N];
int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
G[v].push_back(u);
++d[u];
}
for(int i = ; i <= n; ++i) if(!d[i]) q.push(i);
for(int i = n; i; --i)
{
int x = q.top();
q.pop();
c[x] = i;
for(int j = ; j < G[x].size(); ++j)
{
int v = G[x][j];
--d[v];
if(!d[v]) q.push(v);
}
}
for(int i = ; i <= n; ++i) printf("%d ", c[i]);
return ;
}
F dp dp[i]=min(dp[j-1]+calc(j, i)),calc可以先预处理lcp,然后暴力枚举串的长度,看是否符合 这个跑不过去,要4s
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n;
int dp[N][N], f[N], sum[N];
char s[N];
int getlen(int x)
{
int ret = ;
while(x)
{
++ret;
x /= ;
}
return ret;
}
int main()
{
scanf("%s", s + );
n = strlen(s + );
for(int i = n; i; --i)
for(int j = n; j >= i; --j)
if(s[i] == s[j])
dp[i][j] = dp[i + ][j + ] + ;
memset(f, 0x3f3f, sizeof(f));
f[] = ;
for(int i = ; i <= ; ++i) sum[i] = sum[i / ] + ;
for(int i = ; i <= n; ++i)
for(int j = i; j; --j)
for(int k = i - j + ; k > && dp[k][i - j + ] >= j; k -= j)
f[i] = min(f[i], f[k - ] + j + sum[(i - k + ) / j]);
printf("%d\n", f[n]);
return ;
}
G dfs 思路很好,把第一个变成黑点的点作为根,然后预处理出每个点到根的最小值,每次查询直接拿自己的最小值和上次答案比较,因为上次的答案这次肯定也能用,更新就是把当前的最小值和ans取min
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int opt, x, n, q, last, ans = << ;
int up[N];
vector<int> G[N];
void dfs(int u, int last)
{
for(int i = ; i < G[u].size(); ++i)
{
int v = G[u][i];
if(v == last) continue;
up[v] = min(v, up[u]);
dfs(v, u);
}
}
int main()
{
scanf("%d%d", &n, &q);
for(int i = ; i < n; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
scanf("%d%d", &opt, &x);
x = (x + last) % n + ;
up[x] = x;
dfs(x, );
q--;
while(q--)
{
scanf("%d%d", &opt, &x);
x = (x + last) % n + ;
if(opt == ) ans = min(ans, up[x]);
if(opt == )
{
printf("%d\n", min(ans, up[x]));
last = min(ans, up[x]);
}
}
return ;
}
codeforces educational round 25的更多相关文章
- Codeforces Beta Round #25 (Div. 2 Only)
Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...
- Codeforces Educational Round 33 题解
题目链接 Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- [CodeForces]Educational Round 52
幸好我没有打这场,我VP的时候在C题就卡死了,我果然还是太菜了. A Vasya and Chocolate 题意:一个巧克力\(c\)元,买\(a\)赠\(b\),一共有\(n\)元,问能买几个巧克 ...
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...
- Codeforces Educational Round 37
Solved CodeForces 920A Water The Garden Solved CodeForces 920B Tea Queue Solved CodeForces ...
- Codeforces Educational round 58
Ediv2 58 随手AK.jpg D 裸的虚树,在这里就不写了 E 傻逼贪心?这个题过的比$B$都多.jpg #include <cstdio> #include <algorit ...
- Codeforces Educational Round 57
这场出题人好像特别喜欢998244353,每个题里都放一个 A.Find Divisible 考察选手对输入输出的掌握 输出l 2*l即可(为啥你要放这个题,凑字数吗 #include<cstd ...
- Codeforces Beta Round #25 (Div. 2)--A. IQ test
IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- 数组array的常用方法简介
数组方法简介 数组总共有22种方法,本文将其分为以下几类来进行详细介绍. 原数组变化:push() pop() shift() unshift() reverse() sort() splice() ...
- ie6,ie7,ie8,FF 浏览器兼容问题
javascript部分 1. document.form.item 问题问题:代码中存在 document.formName.item("itemName") 这样的语句,不能在 ...
- UVA-1599 Ideal Path(双向BFS)
题目: 给一个n个点m条边(2≤m≤100000, 1≤m≤200000)的无向图,每条边上都涂有一种颜色(用1到1000000000表示).求从结点1到结点n的一条路径, 使得经过的边数尽量少,在此 ...
- Redis多实例配置以及主从同步
一.多实例配置 1.准备俩配置文件,开两个就准备两个 redis-6380.conf redis-6381.conf 2.分别写入配置信息(这里简化了配置) # 运行在6380端口 bind 172. ...
- 挂载本地file到容器中
-v /Us……/cts/fffen:/usr/local/src -v 标记 将本地主机的目录 到 目标容器的路径下 在容器中查看:ls 发现已经存在py文件 运行python fenci.py ...
- concepts in Turbulent Flow
Table of Contents 1. Concepts/Glossary 1.1. Turbulent eddy viscosity ,μt 1.2. Turbulent kinetic ener ...
- BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏
直接模拟2333 #include<cstdio> #include<algorithm> using namespace std; int n,ans; void read( ...
- 基于XML文档的声明式事务配置
<!-- 配置事务切面 --> <aop:config> <aop:pointcut expression="execution(* com.atguigu.t ...
- codeforces 371B - Fox Dividing Cheese
#include<stdio.h> int count; int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); ...
- Jquery 实现表单提交按钮变灰,防止多次点击提交重复数据
表单提交时候我们应该控制提交按钮,不能点击多次进行数据的重复提交.要不然就会有冗余的重复的数据在系统中,造成系统出现数据垃圾.jQuery很简单的就可以实现对表单提交按钮控制,下面就是相关的例子和代码 ...