codeforce能用万能头文件吗_Good Bye 2020(CodeForces2020.12.30场10:35--1:35)

最近考试都已经结束了,元旦后有两个课程设计,这几天很清闲。

昨晚第一次参加CodeForces比赛,上来就遇到一个纪念场哈,再见2020~

一个半小时才A了第一题,第二题没做出来,菜狗我都不配诶。希望Good Bye 2021的时候我的水平大大提高嗷,定个小目标A4题吧哈哈。

和Tourist他们同场竞技可太棒了!(虽然我只是个小丑哈哈哈哈,他们一分半就把A题A掉了,我一个半小时······

最后Rating变成了368,不应该是从0开始吗?初始分咋成100啦?

e07eb51a74f6bf5b51ea8899d59bbc1f.png

下面来看看Tourist的A题,顺便把B题补了。

A题

题意:给定一组数,求他们之间有多少个不同的非零的差。

我的思路:开int数组,hash,最后遍历整个数组找非零的个数。

上Tourist代码,思路差不多。

/**

* author: tourist

* created: 30.12.2020 17:34:56

**/

#include

using namespace std;

int main() {

ios::sync_with_stdio(false);

cin.tie(0);

int tt;

cin >> tt;

while (tt--) {

int n;

cin >> n;

vector x(n);

for (int i = 0; i < n; i++) {

cin >> x[i];

}

set s;

for (int i = 0; i < n; i++) {

for (int j = i + 1; j < n; j++) {

s.insert(x[j] - x[i]);

}

}

cout << s.size() << '\n';

}

return 0;

}

#include //万能头文件,可自己配置,不多说了

ios::sync_with_stdio(false); //关闭兼容、关闭输入、输出缓存,提高cin、cout效率

cin.tie(0); //解除cin、cout绑定,进一步提高效率

vector x(n); //最大容量为n的可变数组

set s; //集合(元素唯一),正好解决了要找不同差的问题

B题

题意:给定一组数,每个数可以充当自己或者比它大1的数,问这一组数最多可充当多少种不同的数。

我····面向样例编程,不太行,直接上Tourist代码

应该是个思维题,我看不懂T神的代码,尴尬。找了个rank21的中国大佬的代码~

#include

using namespace std;

int t, n, a[100010];

inline void rmain() {

scanf("%d", &n);

for (int i = 1; i <= n; i++) scanf("%d", a + i);

int ans = 1;

for (int i = 2; i <= n; i++) {

if (a[i] <= a[i - 1]) a[i]++;

if (a[i] != a[i - 1]) ans++;

}

printf("%d\n", ans);

}

int main() {

scanf("%d", &t);

while (t--) rmain();

}

if (a[i] <= a[i - 1]) a[i]++; //啊,脑袋~

if (a[i] != a[i - 1]) ans++;

学到了,自己敲了一个,呜呜呜,好难想。2020最后一天,继续加油嗷~

#include

#include

using namespace std;

int t;

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cin>>t;

int n;

while(t--){

cin>>n;

vectora(n);

for(int i=0;i

cin>>a[i];

}

int ans=1;

for(int i=1;i

if(a[i]<=a[i-1]) a[i]++;

if(a[i]!=a[i-1]) ans++;

}

cout<

}

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值