## Problem A

A - Meeting of Old Friends

CodeForces - 714A

题意:

解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点。

题解:

C++版本一

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath> int main()
{
long long int l1,r1,l2,r2,k,x,y;
scanf("%lld%lld%lld%lld%lld",&l1,&r1,&l2,&r2,&k);
x=(l1>=l2)?l1:l2;
y=(r1<=r2)?r1:r2;
if(r1<l2||r2<l1)
{
printf("0\n");
}
else
{
if(x<=k&&k<=y)
{
printf("%lld\n",y-x);
}
else
{
printf("%lld\n",y-x+);
}
}
return ;
}

## Problem B

B - Filya and Homework

CodeForces - 714B

题意:

给定一个序列,对于每一个元素,只能 + 或者 - 一个数val。这个数一旦选定,就不能改。

问能否变成全部数字都一样。

题解:

这题的正解是观察法。也可以证明。

①、全部数字都一样、有两个不同数字、三个不同数字(a[1] + a[3] =  2 * a[2])这些都易懂

那4个不同数字为什么是no呢

可以想象成找不到一个点,作为圆心,包含另外3个点(这3点在一直线)。

所以对于有三个不同数字那个,其实就是判断是否为圆心。

C++版本一

#include <bits/stdc++.h>
using namespace std;
const int N = +;
int a[N];
int main(int argc, char const *argv[])
{
int n;
cin >> n ;
for(int i = ;i <= n ; i ++) cin >> a[i];
sort(a + , a + + n );
int x = unique(a+,a + n+) - a - ;
//cout << a[1] << a[2] << a[3] << a[4] << endl;
//cout << x << endl;
if(x < || (x == &&a[] - a[] == a[] - a[] )){
cout << "YES" << endl;}
else cout << "NO" << endl;
return ; }

## Problem C

C - Sonya and Queries

CodeForces - 714C

题意:

题解:

字典树

C++版本一

#include <bits/stdc++.h>
using namespace std;
const int N = +;
struct Trie
{
int ch[N][];
int sz;
int val[N];
void Init()
{
sz=;
memset(ch,,sizeof ch);
memset(val,,sizeof val);
} void Insert(char *num,int op)
{
int u=;
for(int i=;i>=strlen(num);i--)
{
if(ch[u][]==)
ch[u][]=sz++;
u=ch[u][];
}
for(int i=;i<strlen(num);i++)
{
int c=(num[i]-'')%;
if(ch[u][c]==)
ch[u][c]=sz++;
u=ch[u][c];
}
val[u]+=op;
} int Find(char *num)
{
int u=;
int cur=;
for(int i=;i>=strlen(num);i--)
{
if(ch[u][]==)
return ;
u=ch[u][];
cur+=val[u];
}
for(int i=;i<strlen(num);i++)
{
int c=(num[i]-'')%;
if(ch[u][c]==)
return ;
u=ch[u][c];
cur+=val[u];
}
return cur;
}
};
Trie trie;
int main()
{
trie.Init();
int q;
scanf("%d",&q);
getchar();
while(q--)
{
char s[];
char x[];
scanf("%s%s",s,x);
//cout<<"x="<<x<<endl;
if(s[]=='+')
trie.Insert(x,);
if(s[]=='?')
printf("%d\n",trie.Find(x));
if(s[]=='-')
trie.Insert(x,-);
}
return ;
}

## Problem D

D - Crazy Computer

CodeForces - 716A

题意:

题意:录入n个数,c为临界值,如果n个数中相邻的相减小于c就记录如果有一次不满足就删去前面记录的数,最后输出屏幕上存了几个数。

题解:

题意:录入n个数,c为临界值,如果n个数中相邻的相减小于c就记录如果有一次不满足就删去前面记录的数,最后输出屏幕上存了几个数。

C++版本一

#include <bits/stdc++.h>
using namespace std;
const int N = +;
int a[N]; int main(int argc, char const *argv[])
{
int n , k;
cin >> n >> k ;
long long sum = ;
for(int i = ;i <= n ;i ++){
int x;
//cin >> x;
cin >> a[i];
if(a[i] - a[i - ] > k) sum = ;
sum ++; }
cout << sum << endl;
return ;
}

## Problem E

E - Complete the Word

CodeForces - 716B

题意:

题目要求的是输出全部字符串!不是满足条件的子串!!

题解:

从前往后暴力搜索满足条件的即可,依次搜26个字母。

当然如果总长度小于26肯定输出-1。

最后处理好?的填充处理就行了。

C++版本一

#include <bits/stdc++.h>
using namespace std;
const int N = +;
int a[N];
int vis[];
char str[];
int main(int argc, char const *argv[])
{
//string str;
cin >> str;
int n = strlen(str);
int i = ;
if(n < ) {
printf("-1\n");
return ;
}
bool flag = ;
for(int i = ;i <= n - && flag; i ++){
int tail1 = , tail2 = ;
memset(vis,,sizeof vis);
for(int j = i;j < i + ;j ++){
if(str[j] >= 'A' && str[j] <= 'Z'){
// cout << str[j] - 'A' << " " << j - i << endl;
vis[str[j] - 'A'] ++;
}else tail2 ++;
// if(j = i + 25) break;
}
for(int j = ;j < ;j ++){
if(vis[j] == )
tail1 ++;
}
if(tail1 + tail2 == ){
int t = ;
for(int j = i;j < i + ;j ++){
if(str[j] == '?'){
for(;t < ;t ++){
if(vis[t] == ){
str[j] = 'A' + t;
t++;
break;
}
}
}
}
flag = ;
} //if(flag)
}
for(int i = ;i < n;i ++){
if(str[i] == '?'){
str[i] = 'A';
}
}
if(flag) cout << - << endl;
else cout << str << endl;
return ;
}

## Problem F

F - Plus and Square Root

CodeForces - 716C

题意:

题意:开始给你个数x=2,然后等级k为1,然后开始加等级k,如果x是完全平方数并且开方后是k+1的倍数,就对x开方,然后等级增加一级,问每升高一级需要加多少次

题解:

找规律

等级k      初始数字       加的次数*等级k       得到x         开根号后的x                       关系

√x  /  (k+1) = k

1               2                   +2 * 1                 4                     2                           2   /  2   =  1

2               2                   +17 * 2              36                    6                           6   /  3   =  2

3               6                   +46 * 3              144                  12                        12  /  4   =  3

4              12                  +97 * 4              400                  20                        20  /  5   =  4

所以可以得到关系递推式:

(k-1)*k       +       k*n         =         ( k*(k+1))²

上一级开根         次数*等级                  新的完全平方数x

号得到的x

所以每次所需要加的次数n =( (k*(k+1))² - (k-1)*k)/k  = k*(k+1)² - (k-1)

C++版本一

#include <bits/stdc++.h>
using namespace std;
const int N = +;
int a[N];
int vis[];
char str[]; int main(int argc, char const *argv[])
{
long long n ;
cin >> n ;
if(n == ){
cout << "" << endl;
}
else{
//int ans = 2;
cout << "" << endl;
//3int k = 2;
for(long long i = ;i <= n ;i ++){
cout << (i * (i + )*(i+) - i + ) << endl;
// k = sqrt(k * (i + 1) + 1);
// ans ++;
}
}
return ;
}

CSUST 8.5 早训的更多相关文章

  1. CSUST 8.4 早训

    ## Problem A A - Memory and Crow CodeForces - 712A 题意: 分析可得bi=ai+ai+1 题解: 分析可得bi=ai+ai+1 C++版本一 #inc ...

  2. CSUST 8.3 早训

    A - Settlers' Training CodeForces - 63B 题意 给你一串数字,相同的数字为一组,每次可以给一组中的一个数字加一,问这一串数字全变成K需要多少步? 题解 模拟 C+ ...

  3. B - Planning 早训 贪心

    B - Planning 这个题目我知道要贪心,也知道怎么贪,但是写不出来,感觉自己好菜. 这个题目要用优先队列维护. 题目大意是飞机延误,不同的飞机每次延误一分钟,它的代价不同,然后问,怎么安排才能 ...

  4. 获取技能的成功经验和关于C语言学习的调查 2015528

    内容提要 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 有关C语言学习的调查 你是怎么学习C语言的?(作业,实验,教材,其他 ...

  5. 20155228 获取技能的成功经验和关于C语言学习的调查

    内容提要 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 有关C语言学习的调查 你是怎么学习C语言的?(作业,实验,教材,其他 ...

  6. 吐泡泡(2018年全国多校算法寒假训练营练习比赛(第二场)+栈模拟)+Plug-in(codeforces81A+栈模拟)

    吐泡泡题目链接:https://www.nowcoder.com/acm/contest/74/A 题目: 思路: 这种题目当初卡了我很久,今天早训时遇到一个一样得题,一眼就想到用栈模拟,就又回来把这 ...

  7. B - Save the problem! CodeForces - 867B 构造题

    B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错 ...

  8. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  9. C. Journey bfs 拓扑排序+dp

    C. Journey 补今天早训 这个是一个dp,开始我以为是一个图论,然后就写了一个dij和网络流,然后mle了,不过我觉得如果空间开的足够的,应该也是可以过的. 然后看了题解说是一个dp,这个dp ...

随机推荐

  1. guava中Multimap、Multiset使用

    guava中的Multimap接口 Multimap和java.util.Map接口没有任何继承关系.同Map一样,也是放键值对,但是Multimap的值是一个集合.同样支持泛型,假如键值对的key的 ...

  2. 实战build-react(二)-------引入Ant Design(增加)

    https://blog.csdn.net/zhan_lijian/article/details/85271906(copy) 1.肯定参考facebook关于react官网咯 快速搭建 creat ...

  3. UML——概述

    1. 静态视图(类图)      静态视图不描述与时间相关的系统行为,这种行为在其他视图中描述,因此称之为静态试图.      静态视图用类图来实现,正因为它以类图为中心,因此也称之为类图.     ...

  4. 密度聚类 DBSCAN

    刘建平:DBSCAN密度聚类算法 https://www.cnblogs.com/pinard/p/6208966.html API 的说明: https://www.jianshu.com/p/b0 ...

  5. java生成二维码的几种方式

    1: 使用SwetakeQRCode在Java项目中生成二维码 http://swetake.com/qr/ 下载地址 或着http://sourceforge.jp/projects/qrcode/ ...

  6. Python For Mac 开发环境安装 以及问题记录

    Python For Mac 开发环境安装记录 把自己安装的过程记录一下,亲测可用 1.Python3环境安装(转载http://www.cnblogs.com/meng1314-shuai/p/90 ...

  7. visudo编辑sudoers

    [root@b ~ ]# visudo   #编辑配置文件 相当于vim /etc/sudoers文件 root用户名(谁) ALL任何主机(哪里)=(ALL) 以什么身份(可以切换到所有用户下) a ...

  8. FineReport打印方式(转)

    1. 报表打印机制 各种打印的运行机制,都是选择打印时,先根据报表内容,在服务器的内存中将页面中的内容全部生成完毕,即生成对应格式的对象:然后再由serverlet直接推送给客户端,最后根据选择的打印 ...

  9. Hook exe 和 file

    c#拦截程序的运行 EasyHook  + win7 64位 LocalHook.GetProcAddress("Kernel32.dll", "CreateProces ...

  10. node服务通过Jenkins上线流程

    构建流程 构建服务器: 拉取指定分支代码 构建服务器: 安装依赖 构建服务器: 执行构建 构建服务器: 如果上线流程,则在 git 上创建 tag,供回滚使用 构建服务器:打包 node 服务代码,和 ...