Codeforces Round #674 (Div. 3)

题目传送门

A. Floor Number

签到

Codeforces Round #674 (Div. 3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
 
int n, x;
 
inline void solve(int T)
{
    cin >> n >> x;
    if(n <= 2) cout << "1" << endl;
    else {
        n -= 2;
        cout << ceil(1.0 * n / x) + 1 << endl;
    }
}
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("ans.txt", "w", stdans);
 
    int T = 1;
    cin >> T;
    rep(i, 1, T) solve(i);
}
View Code

 

B. Symmetric Matrix

容易发现只需要一个右上角等于左下角的矩阵就可以构造任意偶数大小的矩阵

Codeforces Round #674 (Div. 3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
 
int n, m;
int a[4], flag, cnt;
 
inline void solve(int T)
{
    cin >> n >> m;
    flag = 0;
    rep(i, 1, n) {
        rep(j, 0, 3) cin >> a[j];
        if(a[1] == a[2]) flag = 1;
        
    }
    if((m & 1) || (!flag)) cout << "NO\n";
    else cout << "YES\n";
}
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("ans.txt", "w", stdans);
 
    int T = 1;
    cin >> T;
    rep(i, 1, T) solve(i);
}
View Code

 

C. Increase and Copy

贪心的想法:先将1加x,再把$x+1$复制y份,答案要满足$(x+1)*y>=n$

答案最多$63244$,可以直接枚举x

Codeforces Round #674 (Div. 3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
 
 
inline void solve(int T)
{
    int n, ans = 63244;
    cin >> n;
    rep(i, 0, 63244) if(i - 1 + ceil(1.0 * n / (i + 1)) < ans) ans = i - 1 + ceil(1.0 * n / (i + 1));
    cout << ans << endl;
}
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("ans.txt", "w", stdans);
 
    int T = 1;
    cin >> T;
    rep(i, 1, T) solve(i);
}
View Code

 

D. Non-zero Segments

如果$1$至$i-1$没有和为$0$的子段,且$1$至$i$存在和为$0$的子段,那就在$i-1$和$i$之间插入一个值,值是什么不重要

大概就是这样贪

Codeforces Round #674 (Div. 3)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)
 
map<ll, ll> mp;
ll n;
ll tmp, sum, ans;
 
inline void solve(int T)
{
    mp.clear();
    sum = ans = 0;
    cin >> n;
    rep(i, 1, n) {
        cin >> tmp;
        sum += tmp;
        if(mp[sum] || sum == 0) ans++, mp.clear(), sum = tmp;
        mp[sum] = 1;
    }
    cout << ans << endl;
}
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("ans.txt", "w", stdans);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
}
View Code

 

上一篇:674. 最长连续递增序列


下一篇:Leetcode 674.最长递增序列