## 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. PHP基础教程探讨一些php编程性能优化总结

      兄弟连PHP培训 小编最近在做php程序的性能优化,一些经过测试后发现的东西就先记录下来,以备后用. 首先对于一些反应慢的操作或页面要跟踪处理一下,可以使用webGrind的方式看一下主要问题出在 ...

  2. mac 绑定阿里企业邮箱

    注意事项: 1. 收件服务器 千万得写对, 选 pop 就写 pop.mxhichina.com; 选 imap 就写 imap.mxhichina.com 2. 发件服务器 必须写,smtp.mxc ...

  3. Android 5种Toast特效

    Toast是Android中用来显示显示信息的一种机制,和Dialog不一样的是,Toast是没有焦点的,而且Toast显示的时间有限,过一定的时间就会自动消失.   1.默认效果: Toast.ma ...

  4. JMS学习六(ActiveMQ消息传送模型)

    ActiveMQ 支持两种截然不同的消息传送模型:PTP(即点对点模型)和Pub/Sub(即发布 /订阅模型),分别称作:PTP Domain 和Pub/Sub Domain. 一.PTP消息传送模型 ...

  5. Jedis下的ShardedJedis

    jedis客户端操作redis主要三种模式:单台模式.分片模式(ShardedJedis).集群模式(BinaryJedisCluster) ShardedJedis是通过一致性哈希来实现分布式缓存的 ...

  6. python3.7--pycharm selenium自启360浏览器/360极速浏览器方法

    写于:2019.01.02(实测日) 参考文档:https://blog.csdn.net/five3/article/details/50013159 一.下载360浏览器或360极速浏览器的Chr ...

  7. PHP mac localhost 环境下发送邮件

    转载自:http://mabblog.com/blog/2011/09/lion-smtp-postfix-relay-and-dreamhost/ When developing web-apps ...

  8. 一个Qt线程的例子,用于说明QWaitCondition的作用

      描述可能比较麻烦,还是直接上代码吧! main.cpp #include <QApplication> #include "mainpage.h" int main ...

  9. ES6 暂时性死区

    在ES6中,声明变量新增了两个关键字:let命令和const命令 如果在区块中存在let或者const命令时,任何变量都必须在声明之前使用,无论是区块外部的全局变量或者是区块内部的变量: /* 区块外 ...

  10. 微博获取原图时重定向到图片的url

    微博获取原图时重定向到图片的url,所以获取的是乱码 jsoup默认是执行重定向的. //根据Url获取页面对应的Document public static Document getDoc1(Str ...