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 ...
随机推荐
- bazel和TensorFlow安装
bazel安装:https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu 安 ...
- 当点阵字库遇到3D
早在遥远的DOS时代,点阵汉字库为计算机处理汉字起到了关键作用.当时的显示器在图形模式下的分辨率只有640x480甚至320x200,显示汉字直接使用点阵字库在屏幕上打点就可以了.如今的电脑屏幕甚至手 ...
- (C/C++学习)18.C语言双向链表
说明:数组提供了连续内存空间的访问和使用,而链表是对内存零碎空间的有效组织和使用.链表又分为单向链表和双向链表,单向链表仅提供了链表的单方向访问,相比之下,双向链表则显得十分方便. 一.单向链表的节点 ...
- MySQL数据导入sql文件过程中出错
错误类型: ERROR 1231 (42000): Variable 'time_zone' can't be set to the value of 'NULL' ERROR 1231 (42000 ...
- 常量、变量;基本数据类型;input()、if、while、break、continue
一.编译型语言和解释型语言区别:编译型:一次性将所有程序编译成二进制文件 缺点:开发效率低,不能跨平台 优点:运行速度快. 例如:C,C++等解释型:当程序执行时,一行一行的解释 优点:开发效率高,可 ...
- CCF201612-2 工资计算 java(100分)
试题编号: 201612-2 试题名称: 工资计算 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 小明的公司每个月给小明发工资,而小明拿到的工资为交完个人所得税之后的工资.假 ...
- idea 获取当前git最新分支
菜单栏VCS->选中Git 选择Fetch 获取最新分支
- selectByExampleWithBLOBs-----搜索结果包含大字段类型----搜索结果包含大字段类型
http://www.jb51.net/article/121482.htm mybatis generator 使用方法教程(生成带注释的实体类)
- HDU 482 String
String Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 482 ...
- poj 1659 判断是否能构成图Havel-Hakimi定理
//用到了Havel-Hakimi定理,判断是否能够构图 //两种情况不能构图,1:对剩下序列排序后,最大的度数超过了剩下的顶点数 // 2:对最大的度数后面的f个度数减-后,出现了负数 //记录到临 ...