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, ...
随机推荐
- Linux系统定时任务crond那些事
1 Linux系统定时任务 1.1 定时任务介绍 1.1.1 Crond是什么? Crond是linux系统中用来定期执行命令或指定程序任务的一种服务或软件.Centos5/ linux系统安装完操作 ...
- 微信小程序scroll-viwe遇到的问题
1.当使用scroll-view的时候里面不可以使用某些标签 2.当使用scroll-view的时候会出现,子元素中滑动的时候会出现滚动的情况,我遇到的是因为view设置了高度和行高,一旦设置了这个, ...
- JQ 封装全选函数
单击时触发效果: 如果有一个没有选中把全选的勾去了,如果select所有的都选中了,那就把全选勾上 html里: <div class="row cl"> <la ...
- 《python编程从入门到实践》第六章笔记
1.字典 字典:一系列键-值对,每一个键都与每一个值相关联.与键相关联的值可以是数字.字符串.列表和字典. 最简单的字典只有一个键值对. eg: alien = {'color':'green','p ...
- Leecode刷题之旅-C语言/python-100相同的树
/* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree ...
- R语言学习笔记(十):零碎知识点(21-25)
21--assign() assign函数可以通过变量名的字符串来赋值 > assign('a', 1:3) > a [1] 1 2 3 > b <- c('a') > ...
- P1049 装箱问题
装箱问题 题目描述 有一个箱子容量为V(正整数,0<=V<=20000),同时有n个物品(0<n<=30,每个物品有一个体积(正整数). 要求n个物品中,任取若干个装入箱内,使 ...
- delphi 数据库中Connection与Query连接数量问题思考
今天闲着没事,测试了一下Connection连接MSSQL,可以承受多少连接. 1.看看ADOConnection的连接数:写了一个代码,动态创建,测试了10000个连接,花了大约5~10分钟创 ...
- Android系统自带样式
android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式 android:theme="@andr ...
- 序列化反序列化--Xstream的使用
之前讲了fastjson的使用--将JavaBean与json对象之间互相转换. 该篇文章,教大家使用Xstream来实现XMl与JavaBean的转换. 第一步: 通过maven引入XStream的 ...