最近在使用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数据结构(水题)小结的更多相关文章

  1. Pearls in a Row CodeForces 620C 水题

    题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对 ...

  2. 【Codeforces自我陶醉水题篇~】(差17C code....)

    Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...

  3. CodeForces 327B 水题。

    I - 9 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. Codeforces - 631B 水题

    注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...

  5. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  6. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  7. Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题

    题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...

  8. 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 ...

  9. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

随机推荐

  1. fullPage.js全屏滚动插件API

    API sectionsColor:['green','orange','red','lime']; //设置背景颜色 可以为每一个section设置background-color属性 contro ...

  2. MySQL 清除表空间碎片

    碎片产生的原因 (1)表的存储会出现碎片化,每当删除了一行内容,该段空间就会变为空白.被留空,而在一段时间内的大量删除操作,会使这种留空的空间变得比存储列表内容所使用的空间更大; (2)当执行插入操作 ...

  3. 一些android的日常笔记

    1.textview文本:如果内容多的话,设置下面的一行代码,可以实现滑动. text.setMovementMethod(ScrollingMovementMethod.getInstance()) ...

  4. python-三级菜单的优化实现

    三级菜单需求: 1.可依次选择进入各子菜单 2.可从任意一层往回退到上一层 3.可从任意一层退出程序 所需新知识点:列表.字典 先通过字典建立数据结构 #创建字典 city_dic = { " ...

  5. 嵌入式Linux系统移植(二)——交叉编译工具集

    常用工具:readelf.size.nm.strip.strings.objdump.objcopy.addr2line readelf:读可执行文件的elf头 ELF Header: Magic: ...

  6. Go语言使用百度翻译api

    Go语言使用百度翻译api 之前做过一个使用百度翻译api的工具,这个工具用于用户的自动翻译功能,是使用C#调用百度翻译api接口,既然在学习Go语言,那必然也是要使用Go来玩耍一番.这里我是这么安排 ...

  7. 线程基础四 使用Monitor类锁定资源

    前面我们讲过了lock的用法以及竞争条件导致的错误,实际上lock关键字是Monitor类用例的一个语法糖.如果我们分解使用了lock关键字的代码,将会看到它如下面代码片段所示: bool acqui ...

  8. Hadoop学习(一) Hadoop是什么

    Hadoop是什么? Hadoop是一个开发和运行处理大规模数据的软件平台,是Appach的一个用Java语言实现开源软件框架,实现在大量计算机组成的集群中对海量数据进行分布式计算. Hadoop框架 ...

  9. ORACLE中order by造成分页不正确原因分析

     工作中遇到的问题: 为调用方提供一个分页接口时,调用方一直反应有部分数据取不到,且取到的数据有重复的内容,于是我按以下步骤排查了下错误. 1.检查分页页码生成规则是否正确. 2.检查SQL语句是否正 ...

  10. 《数据结构与算法分析:C语言描述》读书笔记

    我们数据结构的课用了这本英文教材,作者是Mark Allen Weiss.总体来说比<算法导论>简单很多,但内容上交集非常大.其实是因为去掉了大多数证明和数学,对于没有耐心看符号和公式的人 ...