Codeforces数据结构(水题)小结
最近在使用codeblock,所以就先刷一些水题上上手
使用codeblock遇到的问题
1.无法进行编译-------从setting中的编译器设置中配置编译器
2.建立cpp后无法调试------只建立源文件无法调试,需要建立一个工程后才能调试
3.设置断点后,调试不会停止------开启-g模式且工程要建立在一个没有中文名的文件夹下
4.调试中如何查看变量------打开debug中的watch,右键编辑界面的变量可以选择添加变量
水题来源---codeforces(hzwer神犇刷的水题)
570C.Replacement
给定一个长为n的字符串(包含小写字母和’.’),有m次操作
每次操作可以修改字符,并询问修改后有多少对相邻的’.’
1≤n,m≤105
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
int n, q, N = ;
int x; char ch;
string str;
cin>>n>>q>>str;
int l = str.length();
for(int i = l; i >= ; i--) str[i] = str[i-];
str[] = '#'; str[l+] = '#';
for(int i = ; i <= l; i++)
if(str[i] == '.' && str[i-] == '.') N++;
while(q--)
{
cin>>x>>ch;
if(ch != '.')
{
if(str[x] == '.')
{
if(str[x-] == '.') N--;
if(str[x+] == '.') N--;
}
} else
{
if(str[x] != '.')
{
if(str[x-] == '.') N++;
if(str[x+] == '.') N++;
}
}
str[x] = ch;
cout<<N<<endl;
}
}
427B.Prison Transfer
给定长为 n 的序列,以及 c,t
问你有多少个连续的长度为 c 的子串,且序列中没有一个超过 t
#include <iostream>
#include <cstdio>
using namespace std; int main()
{
int n, t, c, N = , ans = , x;
cin>>n>>t>>c;
for(int i = ; i <= n; i++)
{
cin>>x;
if(x <= t) N++;
if(x > t) N = ;
if(N >= c) ans++;
}
cout<<ans<<endl;
}
519B.A and B and Compilation Errors
给定三个序列,长度分别为 n,n-1,n-2,每一行是上一行的序列去掉一个元素
要求输出去掉的元素
题解:直接排序对比即可
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = ;
int n;
int a[maxn], b[maxn], c[maxn];
int main()
{
cin>>n;
for(int i = ; i <= n; i++) cin>>a[i];
for(int i = ; i <= n-; i++) cin>>b[i];
for(int i = ; i <= n-; i++) cin>>c[i];
sort(a+, a++n);
sort(b+, b+n);
sort(c+, c+n-);
for(int i = ; i <= n; i++) if(a[i] != b[i]) { cout<<a[i]<<endl; break; }
for(int i = ; i <= n-; i++) if(b[i] != c[i]) { cout<<b[i]<<endl; break; } }
650A.Watchmen
给定二维平面的n个坐标,求满足曼哈顿距离等于几何距离的点对
题解:按照x排序,再按照y排序,统计出来即可
*注意需要去掉重复点自身构成的点对(简单容斥)
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
struct Point
{
int x, y;
}p[]; bool cmp1(const Point &A, const Point &B)
{ return A.x > B.x; }
bool cmp2(const Point &A, const Point &B)
{ return (A.y == B.y) ? A.x > B.x : A.y > B.y; }
int n;
LL ans = ;
int main()
{
cin>>n;
for(int i = ; i <= n; i++) cin>>p[i].x>>p[i].y;
sort(p+, p++n, cmp1);
LL t = , t2 = ;
for(int i = ; i <=n; i++)
{
if(p[i].x == p[i-].x) t++;
else
{
ans += (t*(t-)/);
t = ;
}
}
ans += (t*(t-)/); t = ;
sort(p+, p++n, cmp2);
for(int i = ; i <= n; i++)
{
if(p[i].x == p[i-].x && p[i].y == p[i-].y) t2++;
else
{
ans -= (t2*(t2-)/);
t2 = ;
}
if(p[i].y == p[i-].y) t++;
else
{
ans += (t*(t-)/);
t = ;
}
}
ans += (t*(t-)/);
ans -= (t2*(t2-)/);
cout<<ans<<endl;
}
466C.Number of Ways
给定长为n的序列aiai,将其分成3个连续子串,要求每个子串的和相同,求划分的方案数
题解:统计所有满足sum[i]*3 = sum[n]的点的数量m;然后倒序枚举,每枚举到sum[i]*3/2 = sum[n]的点,就加上m,每枚举到sum[i]*3 = sum[n]的点,m--,最后输出即可
*注意当m<=0时,及时跳出,不然会使答案减少
#include <iostream>
#include <cstdio>
using namespace std;
int sum[], a[];
int main()
{
int n;
long long f = , ans = ;
cin>>n;
for(int i = ; i <= n; i++) cin>>a[i];
sum[] = a[];
for(int i = ; i <= n; i++) sum[i] = a[i] + sum[i-];
for(int i = ; i < n-; i++) if(sum[i]* == sum[n]) f++;
for(int i = n-; i > ; i--)
{
if(sum[i]* == sum[n]*) ans += f;
if(sum[i]* == sum[n]) f--;
if(f <= ) break; //f会出现负值的情况
}
cout<<ans<<endl;
}
Codeforces数据结构(水题)小结的更多相关文章
- Pearls in a Row CodeForces 620C 水题
题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对 ...
- 【Codeforces自我陶醉水题篇~】(差17C code....)
Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...
- CodeForces 327B 水题。
I - 9 Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Codeforces - 631B 水题
注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
- 水题 Codeforces Round #300 A Cutting Banner
题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...
- Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题
题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
随机推荐
- 图片懒加载 jquery.lazyload
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- MySQL wait_timeout参数修改
MySQL wait_timeout参数修改问题,可能经常会有DBA遇到过,下面就试验一下并看看会有什么现象. wait_timeout分为global级及session级别,如未进行配置,默认值为2 ...
- ThinkPHP创建应用
新建一个文件 引入ThinkPHP文件
- for循环小练习
for循环是前测试循环语句 for(初始值:判定条件:步长){ 循环语句 } For循环原理: For循环第一次执行:首先执行语句1,然后执行语句2,如果条件为真,向内执行执行循环语句3. 如果条件为 ...
- VSCode插件整理
VSCode插件整理 VSCode插件整理 官网地址 vscode常用配置(User Settings文件) 基本插件 前端插件 VUE部分 python MarkDown部分 连接Linux 本地与 ...
- 初识python 文件读取 保存
上一章最后一题的答案:infors.sort(key=lambda x:x['age'])print(infors)--->[{'name': 'laowang', 'age': 23}, {' ...
- 简单整理React的Context API
之前做项目时经常会遇到某个组件需要传递方法或者数据到其内部的某个子组件,中间跨越了甚至三四层组件,必须层层传递,一不小心哪层组件忘记传递下去了就不行.然而我们的项目其实并没有那么复杂,所以也没有使用r ...
- react ant-design自定义图标
ant-design给我们提供的图标不够怎么办呢?答案是我们可以自定义图标. 自定义图标也挺简单的,现在图标推荐用svg格式,那么我们就需要制作svg图片. 下面让我们看看如果制作svg图片吧. 1. ...
- python2.7练习小例子(十八)
19):题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数. #!/usr/bin/python # -*- ...
- 开启一个项目如何上传到git
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...