头像

no_one

yin yin yin




离线:44分钟前


最近来访(401)
用户头像
xiaohu
用户头像
人间过客_追梦人
用户头像
muttly
用户头像
zww
用户头像
垫底抽風
用户头像
奔向未来
用户头像
我敲可爱呀
用户头像
雾璃鸦
用户头像
FHL
用户头像
._565
用户头像
大羊驼
用户头像
加贝努力
用户头像
gangan
用户头像
为斯卡蒂献上心脏
用户头像
Updater
用户头像
回忆总是那么欣慰
用户头像
hnsqls
用户头像
xzx_qwq
用户头像
蜡笔xx
用户头像
77777777777

活动打卡代码 AcWing 4644. 求和

no_one
48分钟前

S数组开LL 不然过不了

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 200010;
int n;
int a[N];
LL s[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= n; i ++) s[i] = a[i] + s[i - 1];

    LL res = 0;
    for(int i = 1; i < n; i ++)
            res += a[i] *(s[n] - s[i]);

    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 4620. 旅行

no_one
1小时前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 300010, M = N * 2;

int n;
int v[N];
int h[N], e[M], w[M], ne[M], idx;
LL f[N];
LL ans;

void add(int a, int b, int c)
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

void dfs(int u, int fa)
{
    LL max1 = 0, max2 = 0;
    for (int i = h[u]; ~i; i = ne[i])
    {
        int j = e[i];
        if (j == fa) continue;
        dfs(j, u);
        if (f[j] - w[i] >= max1)
        {
            max2 = max1;
            max1 = f[j] - w[i];
        }
        else if (f[j] - w[i] > max2)
        {
            max2 = f[j] - w[i];
        }
    }

    ans = max(ans, v[u] + max1 + max2);
    f[u] = v[u] + max1;
}

int main()
{
    scanf("%d", &n);
    memset(h, -1, sizeof h);
    for (int i = 1; i <= n; i ++ ) scanf("%d", &v[i]);

    for (int i = 0; i < n - 1; i ++ )
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        add(a, b, c);
        add(b, a, c);
    }

    dfs(1, -1);

    printf("%lld\n", ans);
    return 0;
}



no_one
18小时前
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int val = -1, pos = -1;
        for (int i = 1; i <= 100; i ++ ) {
            int x = sc.nextInt();
            if (x > val) {
                val = x;
                pos = i;
            }
        }

        System.out.printf("%d\n%d\n", val, pos);
    }
}


活动打卡代码 AcWing 4006. 数组推导

no_one
18小时前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int n;
int b[N];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i ++ ) cin >> b[i];

    int maxs = 0, mins = 0;
    for (int i = 0; i < n; i ++ )
    {
        maxs += b[i];
        if(!i || b[i] > b[i - 1])
            mins += b[i];
    }

    cout << maxs << endl;
    cout << mins << endl;

    return 0;
}



活动打卡代码 AcWing 3257. 跳一跳

no_one
19小时前
/
#include<iostream>
#include<algorithm>

using namespace std;
const int N = 40;
int a[N], f[N];
int idx;


int main()
{
    while(1)
    {
        int x;
        cin >> x;
        if(x == 0) break;
        else a[idx ++] = x;
    }

    for(int i = 0; i < idx; i ++) 
    {
        if(a[i] == 1) f[i] = 1;
        if(a[i] == 2 && a[i - 1] != 2) f[i] = 2;
        if(a[i] == 2 && a[i - 1] == 2) f[i] = f[i - 1] + 2;
    }

    int res = 0;

    for(int i = 0; i < idx; i ++) res += f[i];

    cout << res << endl;

    return 0;
}



no_one
1天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

bool is_pri(int n)
{
    if(n < 2) return 0;

    for(int i = 2; i <= n / i; i ++)
    {
        if(n % i == 0)
        return 0;
    }

    return 1;
}

int main()
{
    int x;
    cin >> x;

    for(int i = 2; i <= x; i ++)
    {
        if(x % i != 0) continue;
        int d = x / i;
        if(is_pri(d) && is_pri(i))
        {
            cout << i << ' ' << d << endl;
            break;
        }
    }


    return 0;
}



no_one
1天前

模拟整个思路,具体见代码

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 200010;
bool yin[N];
int a[N];
int n;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        int x;
        cin >> x;
        if(x >= 2 && x % 2 == 0) yin[i] = true;
        x = x % 2;
        a[i] = x;
    }

    bool res = true;

    for(int i = 0; i < n; i ++)
    {
        if(a[i] == 1 && a[i + 1] == 1) 
        {
            a[i] = 0;
            a[i + 1] = 0;
            continue;
        }
        if(a[i] == 1 && a[i + 1] == 0)
        {
            if(!yin[i + 1])
            {
                res = false;
                break;
            }
            if(yin[i + 1])
            {
                if(a[i + 2] != 1 && !yin[i + 2]) 
                {
                    res = false;
                    break;
                }
            }
            if(yin[i + 1] && a[i + 2] == 1) 
            {
                a[i] = 0;
                a[i + 1] = 0;
                a[i + 2] = 0;
            }
            if(yin[i + 1] && yin[i + 2])
            {
                a[i] = 0;
                a[i + 1] = 0;
                a[i + 2] = 1;
            }
        }
    }

    if(res) cout << "YES" << endl;
    else puts("NO");
    return 0;
}


活动打卡代码 AcWing 3282. 报数

no_one
3天前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int ans[4];

int main()
{
    int n;
    cin >> n;
    int k = 0, i = -1;
    while (n)
    {
        i ++ ;
        k ++ ;
        if (k % 7 == 0 || to_string(k).find('7') != -1) ans[i % 4] ++ ;
        else n -- ;
    }
    for (int i = 0; i < 4; i ++ ) cout << ans[i] << endl;
    return 0;
}




no_one
3天前

过辣

但是有一个问题, 如果是考试,我可能发现不了错误,很离谱

我是提交了知道错了才改的, 如果是考试就没分了

~~~~~~~~~~~~

思路就是模拟, 用一个bool数组记录是否掉落苹果。

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1010;
bool yin[N];
int a[N];
int t;

int main()
{
    cin >> t;
    int cnt = 1;
    int summ = 0, res = 0, ress = 0;
    while (t -- )
    {
        int m;
        cin >> m;
        for(int i = 1; i <= m; i ++) cin >> a[i];
        int ans = a[1];
        int c = 0;
        bool st = false;
        for(int i = 1; i <= m; i ++)
        {
            if(a[i] <= 0) ans += a[i];
            if(a[i] > 0 && ans > a[i])
            {
                ans = a[i];
                if(!st)
                {
                    res ++;
                    yin[cnt] = true;
                    st = true;
                }
            }
        }

        summ += ans;
        cnt ++;
    }

    cnt --;

    for(int i = 2; i <= cnt + 1; i ++)
    {   
        int a = i - 1, b = i + 1, c = i;
        if(a > cnt) a -= cnt;
        if(b > cnt) b -= cnt;
        if(c > cnt) c -= cnt;
        if(yin[a] && yin[b] && yin[c]) ress ++;
    }

    cout << summ << ' ' << res << ' ' << ress;
    return 0;
}




no_one
3天前

过辣

但是有一个问题, 如果是考试,我可能发现不了错误,很离谱

我是提交了知道错了才改的, 如果是考试就没分了

~~~~~~~~~~~~

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1010;
bool yin[N];
int a[N];
int t;

int main()
{
    cin >> t;
    int cnt = 1;
    int summ = 0, res = 0, ress = 0;
    while (t -- )
    {
        int m;
        cin >> m;
        for(int i = 1; i <= m; i ++) cin >> a[i];
        int ans = a[1];
        int c = 0;
        bool st = false;
        for(int i = 1; i <= m; i ++)
        {
            if(a[i] <= 0) ans += a[i];
            if(a[i] > 0 && ans > a[i])
            {
                ans = a[i];
                if(!st)
                {
                    res ++;
                    yin[cnt] = true;
                    st = true;
                }
            }
        }

        summ += ans;
        cnt ++;
    }

    cnt --;

    for(int i = 2; i <= cnt + 1; i ++)
    {   
        int a = i - 1, b = i + 1, c = i;
        if(a > cnt) a -= cnt;
        if(b > cnt) b -= cnt;
        if(c > cnt) c -= cnt;
        if(yin[a] && yin[b] && yin[c]) ress ++;
    }

    cout << summ << ' ' << res << ' ' << ress;
    return 0;
}