1. 程式人生 > 其它 >Good Bye 2020(CodeForces2020.12.30場10:35--1:35)

Good Bye 2020(CodeForces2020.12.30場10:35--1:35)

技術標籤:codeforces

最近考試都已經結束了,元旦後有兩個課程設計,這幾天很清閒。
昨晚第一次參加CodeForces比賽,上來就遇到一個紀念場哈,再見2020~
一個半小時才A了第一題,第二題沒做出來,菜狗我都不配誒。希望Good Bye 2021的時候我的水平大大提高嗷,定個小目標A4題吧哈哈。


和Tourist他們同場競技可太棒了!(雖然我只是個小丑哈哈哈哈,他們一分半就把A題A掉了,我一個半小時······


最後Rating變成了368,不應該是從0開始嗎?初始分咋成100啦?
在這裡插入圖片描述


下面來看看Tourist的A題,順便把B題補了。


A題
題意:給定一組數,求他們之間有多少個不同的非零的差。
我的思路:開int陣列,hash,最後遍歷整個陣列找非零的個數。

上Tourist程式碼,思路差不多。

/**
 *    author:  tourist
 *    created: 30.12.2020 17:34:56       
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
      cin >> x[i];
    }
    set<int> 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 <bits/stdc++.h> //萬能標頭檔案,可自己配置,不多說了
ios::sync_with_stdio(false);  //關閉相容、關閉輸入、輸出快取,提高cin、cout效率
cin.tie(0);  //解除cin、cout繫結,進一步提高效率
vector<int> x(n); //最大容量為n的可變陣列
set<int> s;  //集合(元素唯一),正好解決了要找不同差的問題

B題
題意:給定一組數,每個數可以充當自己或者比它大1的數,問這一組數最多可充當多少種不同的數。

我····面向樣例程式設計,不太行,直接上Tourist程式碼

應該是個思維題,我看不懂T神的程式碼,尷尬。找了個rank21的中國大佬的程式碼~
#include <bits/stdc++.h>
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<iostream>
#include<vector>
using namespace std;
int t; 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>t;
	int n;
	while(t--){
		cin>>n;
		vector<int>a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		int ans=1;
		for(int i=1;i<n;i++){
			if(a[i]<=a[i-1]) a[i]++;
			if(a[i]!=a[i-1]) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}