寒假每日一题(入门组)week3 完结

Posted 辉小歌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寒假每日一题(入门组)week3 完结相关的知识,希望对你有一定的参考价值。

目录

1208. 翻硬币【贪心】


https://www.acwing.com/problem/content/1210/

#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(void)

    cin>>a>>b;
    int cnt=0;
    for(int i=0;i<a.size();i++)
        if(a[i]!=b[i])
        
            if(a[i+1]=='*') a[i+1]='o';
            else a[i+1]='*';
            cnt++;
        
    cout<<cnt;
    return 0;

1532. 找硬币【哈希】


https://www.acwing.com/problem/content/1534/

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
map<int,int>mp;
int a[N],n,m;
int main(void)

    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>a[i],mp[a[i]]++;
    sort(a,a+n);
    for(int i=0;i<n;i++)
    
        if( (mp[m-a[i]]&&m-a[i]!=a[i]) || (m-a[i]==a[i])&&mp[a[i]]>=2)
        
            cout<<a[i]<<" "<<m-a[i];
            return 0;
        
    
    cout<<"No Solution";
    return 0;

1341. 十三号星期五【日期模拟】


https://www.acwing.com/problem/content/1343/

#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int a1,b1,c1,n;
int month[13]=0,31,28,31,30,31,30,31,31,30,31,30,31;
int cnt[10]=0,0;
bool check(int year)

    if(year%400==0||(year%4==0&&year%100!=0)) return true;
    return false;

int main(void)

    cin>>n;
    a=1900,b=1,c=1;
    a1=1900+n-1,b1=12,c1=31;
    int len=1;
    do
    
        if(check(a)) month[2]=29;
        else month[2]=28;
        if(c>month[b]) c=1,b++;
        if(b>12) b=1,a++;
        if(c==13) cnt[len%7]++;
        c++,len++;
    while(a!=a1||b!=b1||c!=c1);
    cout<<cnt[6]<<" "<<cnt[0]<<" ";
    for(int i=1;i<=5;i++) cout<<cnt[i]<<" ";
    return 0;

754. 平方矩阵 II【规律】


https://www.acwing.com/problem/content/756/

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int a[105][105];
int main(void)

    int n;
    while(cin>>n,n)
    
        for(int i=1;i<=n;i++)
        
            for(int j=1;j<=n;j++) cout<<abs(i-j)+1<<" ";
            cout<<endl;
        
        cout<<endl;
    
    return 0;

1432. 棋盘挑战【dfs】


https://www.acwing.com/problem/content/1434/

#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
const int N=15;
int cnt,n,a[N],st[N];
void dfs(int index)

    for(int i=0;i<index;i++)
       for(int j=i+1;j<index;j++)
           if(abs(a[i]-a[j])==abs(i-j)) return;
    if(index==n)
    
        cnt++;
        if(cnt<=3)
        
            for(int i=0;i<n;i++) printf("%d ",a[i]);
            puts("");
        
        return;
    
    for(int i=1;i<=n;i++)
    
        if(!st[i])
        
            st[i]=1,a[index]=i;
            dfs(index+1);
            st[i]=0;
        
    

int main(void)

    cin>>n;
    dfs(0);
    cout<<cnt<<endl;
    return 0;

#include<bits/stdc++.h>
using namespace std;
const int N=40;
int st[N],path[N],a[N],b[N],cnt,n;//st[i]是列 a[i] b[i] 分别是对角线的编号
void dfs(int x)

    if(x==n+1)
    
        cnt++;
        if(cnt<=3)
        
            for(int i=1;i<=n;i++) cout<<path[i]<<" ";
            cout<<endl;
        
        return;
    
    for(int y=1;y<=n;y++)
    
        if(!st[y]&&!a[x-y+n]&&!b[x+y])//列 对角线都没有
        
            path[x]=y,st[y]=1,a[x-y+n]=1,b[x+y]=1;
            dfs(x+1);
            path[x]=0,st[y]=0,a[x-y+n]=0,b[x+y]=0;
        
    

int main(void)

    cin>>n;
    dfs(1);
    cout<<cnt;
    return 0;

1371. 货币系统【DP 完全背包】


https://www.acwing.com/problem/content/1373/

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
typedef long long int LL;
LL a[N],n,m;
LL f[30][N];
int main(void)

    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    f[0][0]=1;
    for(int i=1;i<=n;i++) 
    
        for(int j=0;j<=m;j++)
        
            f[i][j]=f[i-1][j];
            if(j>=a[i]) f[i][j]+=f[i][j-a[i]];
        
    
    cout<<f[n][m]<<endl;
    return 0;

1381. 阶乘【模拟 质因数分解】


https://www.acwing.com/problem/content/1383/

#include<bits/stdc++.h>
using namespace std;
int main(void)

    int n; cin>>n;
    long long int sum=1;
    for(int i=1;i<=n;i++) 
    
        sum*=i;
        while(sum%10==0) sum/=10;
        sum=sum%100000;
    
    cout<<sum%10;
    return 0;

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int n;
void solve(int x)

    for(int i=2;i<=x/i;i++)
    
        while(x%i==0) mp[i]++,x/=i;
    
    if(x!=1) mp[x]++;

int main(void)

    cin>>n;
    for(int i=1;i<=n;i++) solve(i);
    int cnt=min(mp[2],mp[5]);
    mp[2]-=cnt,mp[5]-=cnt;//除掉末尾的零
    int sum=1;
    for(auto i=mp.begin();i!=mp.end();i++)
    
        int k=i->first;
        cnt=i->second;
        for(int j=1;j<=cnt;j++) sum=sum*k%10;
    
    cout<<sum<<endl;
    return 0;

#include<bits/stdc++.h>
using namespace std;
int main(void)

    int sum=1,cnt2=0,cnt5=0,n;
    cin>>n;
    for(int i=1;i<=n;i++)
    
        int x=i;
        while(x%2==0) cnt2++,x/=2;
        while(x%5==0) cnt5++,x/=5;
        sum=sum*x%10;//不含2和5的数
    
    for(int i=1;i<=cnt2-cnt5;i++) sum=sum*2%10;//2的数量一定比5的数量多
    cout<<sum;
    return 0;

以上是关于寒假每日一题(入门组)week3 完结的主要内容,如果未能解决你的问题,请参考以下文章

寒假每日一题(入门组)week7 完结

寒假每日一题(入门组)week4 完结

寒假每日一题(入门组)week1 完结

寒假每日一题(入门组)week5 完结

寒假每日一题(入门组)week6 完结

寒假每日一题(提高组)Week 2 完结