头像

不会算法的小菜鸡




离线:8小时前


最近来访(36)
用户头像
dzzx666
用户头像
yan扬
用户头像
wdsyyds
用户头像
清风乍起
用户头像
EastTree
用户头像
acw_林少
用户头像
Uranus.
用户头像
._7265
用户头像
kk同学
用户头像
slight
用户头像
最傻的猪
用户头像
Luo_gu_ykc
用户头像
yxc
用户头像
zuihe
用户头像
Cantexplain
用户头像
江无聊
用户头像
Bigwave
用户头像
寄寄寄寄摆摆摆摆摆
用户头像
我是老人
用户头像
Soviet_Forever

活动打卡代码 LeetCode 1282. 用户分组

class Solution {
public:
    vector<vector<int>> groupThePeople(vector<int>& groupSizes) {
        vector<vector<int>> res;
        map<int,vector<int>> v;
        for(int i = 0; i < groupSizes.size(); i ++)
        {
           v[groupSizes[i]].push_back(i);
           if(v[groupSizes[i]].size() == groupSizes[i])
           {
               res.push_back(v[groupSizes[i]]);
               v[groupSizes[i]].clear();
           }
        }
        return res;
    }
};


活动打卡代码 AcWing 3589. 平方因子

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        bool flag = true;
        for(int i = 2; i * i <=n; i ++ )
        {
            if(n % (i * i) == 0 )
            {
                cout <<"Yes"<<endl;
                flag = false;
                break;
            }
        }
        if(flag) cout <<"No"<<endl;
    }
}


活动打卡代码 AcWing 3449. 数字根

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

using namespace std;

string s;

int main()
{

    while(cin >> s && s != "0")
    {
        int ans = 0;
        while(ans > 9 || ans == 0)
        {
             ans = 0;
            for(int i = 0; i < s.length(); i ++)
            {
                int t = s[i] - '0';
                ans +=t;
            }
            if(ans > 9) s = to_string(ans);
        }
        cout << ans << endl;
    }

}


活动打卡代码 AcWing 2070. 自行车之旅

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

using namespace std;

const int N = 110;

int a[N];
int t,n;

int main()
{
    cin >> t;

    for(int i = 1; i <= t; i ++)
    {
        int res = 0;
        cin >> n;
        for(int j = 1; j <= n; j ++)
        {
            cin >> a[j];
            if(j >=3)
            {
                if(a[j-1] > a[j] && a[j-1] > a[j-2]) res ++;
            }
        }  
        printf("Case #%d: %d\n",i,res);
        memset(a,-0x3f,sizeof a);
    }
}


活动打卡代码 AcWing 3526. 素数

#include<iostream>
#include<algorithm>

using namespace std;

int n;

bool check(int num)
{
    for(int i = 2; i < num; i ++)
    {
        if(num % i == 0) return false;
    }
    return true;
}
int main()
{
    while(cin >> n)
    {
        bool flag = true;
        for(int i = 11; i < n; i ++)
        {
            if(i%10 == 1) 
            {
                if(check(i))
                {
                    cout << i << " ";
                    flag = false;
                }

            }
        }
        if(flag)
        {
            cout << "-1";
        }
        cout << endl;
    }

}


活动打卡代码 AcWing 4518. 最低票价

#include<iostream>
#include<algorithm>

using namespace std;

const int N = 370;

int days[N],costs[N];
int f[N];
int n;

int get(int i, int cnt)
{
    int  day = i;
    while(day >= 1 && days[day] >= days[i] - cnt + 1 ) day--; //大于等于day[i]的最大cnt天
    return day;
}
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> days[i];
    for(int i = 1; i <= 3; i ++) cin>> costs[i];

    for(int i = 1; i <= n; i++)
    {
        f[i] = f[i-1] + costs[1];
        f[i] = min(f[i],f[get(i,7)] + costs[2]);
        f[i] = min(f[i],f[get(i,30)] + costs[3]);
    }
    cout << f[n];
    return 0;
}


活动打卡代码 AcWing 3644. 水仙花数

#include<iostream>
#include<algorithm>

using namespace std;

int n;
int l ,r;

bool check(int num)
{
    int res = 0;
    int t = num;
    while(num)
    {
        res = (num % 10) * (num % 10) * (num % 10) + res;
        num /= 10;
    }
    if(res == t) return true;
    return false;
}
int main()
{

    while(cin >> l >> r, l || r)
    {
         bool flag = true;
        for(int i =l ; i <= r; i ++)
        {
            if(check(i))
            {
                flag = false;
                cout << i << " ";
            }
        }
        if(flag) cout << "no";
        cout << endl;
    }
}



#include<iostream>
#include<algorithm>

using namespace std;

const int N = 100010;

int f[N],a[N];


int main()
{
    int n;
    while(cin >> n)
    {
        int l = 0,r = 0,temp  = 0;
        for(int i = 1; i <= n; i ++) cin >> a[i];
        int res = -1;
        for(int i = 1; i <= n; i ++)
        {
            f[i] = max(f[i-1] + a[i], a[i]);
            if(f[i - 1] < 0) temp = i - 1;
            if(f[i] > res) 
            {
                res = f[i];
                l = temp;
                r = i-1;
            }

        }
        if(res < 0) cout << "0 0 0 " << endl;
        else cout << res << " " << l <<" " << r << endl;
    }
}


活动打卡代码 AcWing 3619. 日期

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int m,d;
map<int,string> s;

int main()
{
    s[1] = "Monday";
    s[2] = "Tuesday";
    s[3] = "Wednesday";
    s[4] = "Thursday";
    s[5] = "Friday";
    s[6] = "Saturday";
    s[7] = "Sunday";
    cin >> m >> d;
    int a = 4, b = 12, c= 4;

    while(!(a == m && b == d))
    {

        c ++;
        b ++;
        if(a == 5 || a == 7 || a == 8 || a == 10 || a == 12)
        {
            if(b == 32)
            {
                a ++;
                b = 1;
            }
        }
       else
        {
            if(b == 31)
            {
                a ++;
                b = 1;
            }
        }
        if(c > 7) c = 1;


    }
    cout << s[c];
}


活动打卡代码 AcWing 4268. 性感素数

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int n;

int check(int num)
{
    if(num <= 1) return false;
    if(num == 2) return true;
    if(num == 1) return false;
    for(int i = 2; i <= (int)sqrt(num); i ++)
    {
        if(num % i == 0) return false;
    }
    return true;
}

int main()
{
    cin >> n;

    if(check(n) && (check(n-6) || check(n+6) ) )
    {
        cout << "Yes" << endl;
        if(check(n-6)) cout << n-6;
        else cout << n + 6;
    }
    else 
    {
        cout << "No" << endl;
        for(int i = n + 1; i <= 1e8; i ++)
        {
            if(check(i) && (check(i-6) || check(i+6) ))
            {
                cout << i;
                break;
            }
        }
    }
    return 0;
}