最近在使用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. Angular-chart.js 使用说明(基于angular.js工程)

    Angular-chart.js是基于Chart.js的angular组件,引入项目后直接操作数据即可. 引用方法:    分别将Chart.js.angular-chart.js.angular-c ...

  2. jQuery(三)HTML

    获得内容: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - 设置或返回表单字段的值 <html> < ...

  3. Leecode刷题之旅-C语言/python-66加一

    /* * @lc app=leetcode.cn id=66 lang=c * * [66] 加一 * * https://leetcode-cn.com/problems/plus-one/desc ...

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

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

  5. Plsql developer 怎么在打开时登陆配置oracel client?

    配置前 logon 这块是空白的,该怎么配置呢? 看下面 --> 安装完plsql 后 需要安装 oracle client, 这里不再赘述,请自行百度.下面将贴出如何使用 oracle cli ...

  6. HI2115软件开发板V150版本AT+NSOST指令

    1. 在HI2115里面,由于内存空间比较大,所以支持UDP发送指令AT+NSOST的分包 ret = sendto(socket, seq_num, data_string, length, msg ...

  7. 用Kettle的一套流程完成对整个数据库迁移 费元星

    原地址 :http://ainidehsj.iteye.com/blog/1735434 需求: 1.你是否遇到了需要将mysql数据库中的所有表与数据迁移到Oracle. 2.你是否还在使用kett ...

  8. 自定义T4模板去掉实体对象中的下划线

            在EF Power Tool 默认使用的T4模板中,如果数据库表有下划线,那么生成的实体也有下划线,但是我们实际使用的过程中,是不希望有下划线的,要解决这个问题,可以自定义这个T4模板 ...

  9. EntityFramewrok 使用

    1.使用一些查询比较复杂或者需要拼接的查询的时候最好一直保持IQueryable.一直到最后取数据的时候才进行查询.例如分页之类的条件拼接. var query = dbset.Where(expre ...

  10. 第七篇数字&字符串之练习题

    1.执行Python脚本的两种方式2.简述位.字节的关系3.简述ascii.unicode.utf-­‐8.gbk的关系4.请写出“李杰”分别用utf-­‐8和gbk编码所占的位数5.Pyhton单行 ...