一点思维题记录emm

城市规划 【贪心】

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 1000010, M = 10000010;

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
} 

int mp[N],ans,n,m;

int main(){
    freopen("1.txt", "r", stdin);
    n = read(), m = read();
    while(m --){
        int x = read(), y = read();
        if(x > y)    swap(x, y);
        if(!mp[x])    mp[x] = y;
        else    mp[x] = min(mp[x], y); 
    }
    int idx = 1, last = 0;
    while(idx <= n && !mp[idx])    idx ++;
    last = mp[idx];
    for(int i = idx + 1; i <= n; ++ i){
        if(!last && mp[i])    last = mp[i];
        if(i == last)    ans ++, last = mp[i];
        if(!mp[i])    continue ;
        if(mp[i] > last)    continue ;
        else    last = mp[i];
    }
    cout << ans;
    return 0;
}

小P和小Q

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 100010;

int n,t;
ll x, y;

ll ksm(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1)    res = res * a;
        a *= a;
        b >>= 1;
    }
    return res;
}

int main(){
    cin >> t;
    while(t --){
        cin >> x >> y;
        ll tmp = (int)pow(x * y, 1.0 / 3);
        if(ksm(tmp, 3) == x * y || ksm(tmp + 1, 3) == x * y)    puts("Yes");
        else    puts("No");
    }
    return 0;
} 

漂亮的树

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 100010;

int mp[N * 2], a[N], n, maxx;

int main(){
    cin >> n;
    for(int i = 1; i <= n / 2; ++ i){
        scanf("%d", &a[i]);
        mp[a[i] - i + N] ++;
        maxx = max(maxx, mp[a[i] - i + N]);
    }
    for(int i = n / 2 + 1; i <= n; ++ i){
        scanf("%d", &a[i]);
        mp[a[i] - (n - i + 1) + N] ++;
        maxx = max(maxx, mp[a[i] - (n - i + 1) + N]);
    }
    cout << n - maxx;
    return 0;
}

选值

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 100010;

int n,d,a[N];
ll ans;

ll C(ll x){
    return x * (x - 1) / 2;
}

int main(){
    cin >> n >> d;
    for(int i = 1; i <= n; ++ i){
        scanf("%d", &a[i]);
    } 
    for(int i = 1; i <= n; ++ i){
        int tmp = a[i] + d;
        int pos = upper_bound(a + 1, a + 1 + n, tmp) - (a + 1);
        //printf("i = %d tmp = %d pos = %d\n", i, tmp, pos);
        int num = (a[pos] > tmp ? pos - i + 1 : pos - i);
        ans += C(num);
        //printf("num = %d C = %d\n", num, C(num));
    }
    cout << ans;
    return 0;
} 

水题

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

int n;

int main(){
    while(cin >> n){
        int tmp = n / 2;
        printf("%d\n", tmp * (n - tmp));
    }
    return 0;
}

阶乘

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

ll n, ans, last;

int main(){
    cin >> n;
    for(int i = 5; i <= n; ++ i){
        int t = i;
        while(t % 5 == 0){
            t /= 5;
            last ++;
        }
        ans += last;
    }
    cout << ans;
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
11293次浏览 95人参与
# 你的实习产出是真实的还是包装的? #
2011次浏览 42人参与
# MiniMax求职进展汇总 #
24166次浏览 310人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7679次浏览 43人参与
# 简历第一个项目做什么 #
31779次浏览 342人参与
# 重来一次,我还会选择这个专业吗 #
433626次浏览 3926人参与
# 米连集团26产品管培生项目 #
6077次浏览 216人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
187250次浏览 1122人参与
# 牛客AI文生图 #
21454次浏览 238人参与
# 不考虑薪资和职业,你最想做什么工作呢? #
152499次浏览 888人参与
# 研究所笔面经互助 #
118981次浏览 577人参与
# 简历中的项目经历要怎么写? #
310438次浏览 4222人参与
# AI时代,哪些岗位最容易被淘汰 #
63945次浏览 831人参与
# 面试紧张时你会有什么表现? #
30525次浏览 188人参与
# 你今年的平均薪资是多少? #
213177次浏览 1039人参与
# 你怎么看待AI面试 #
180226次浏览 1260人参与
# 高学历就一定能找到好工作吗? #
64344次浏览 620人参与
# 你最满意的offer薪资是哪家公司? #
76595次浏览 374人参与
# 我的求职精神状态 #
448203次浏览 3129人参与
# 正在春招的你,也参与了去年秋招吗? #
363582次浏览 2638人参与
# 腾讯音乐求职进展汇总 #
160699次浏览 1112人参与
# 校招笔试 #
471384次浏览 2964人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务