2022-02-16每日刷打卡

一、AcWing 338. 计数问题

1. 问题描述

img

2. 问题解决

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 10;

int get(vector<int> num, int l, int r)
{
    int res = 0;
    for (int i = l; i >= r; i -- ) res = res * 10 + num[i];
    return res;
}

int power10(int x)
{
    int res = 1;
    while (x -- ) res *= 10;
    return res;
}

int count(int n, int x)
{
    if (!n) return 0;

    vector<int> num;
    while (n)
    {
        num.push_back(n % 10);
        n /= 10;
    }
    n = num.size();

    int res = 0;
    for (int i = n - 1 - !x; i >= 0; i -- )
    {
        if (i < n - 1)
        {
            res += get(num, n - 1, i + 1) * power10(i);
            if (!x) res -= power10(i);
        }

        if (num[i] == x) res += get(num, i - 1, 0) + 1;
        else if (num[i] > x) res += power10(i);
    }

    return res;
}

int main()
{
    int a, b;
    while (cin >> a >> b , a)
    {
        if (a > b) swap(a, b);

        for (int i = 0; i <= 9; i ++ )
            cout << count(b, i) - count(a - 1, i) << ' ';
        cout << endl;
    }

    return 0;
}

二、AcWing 291. 蒙德里安的梦想

1. 问题描述

img

2. 问题解决

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

using namespace std;

typedef long long LL;

const int N = 12, M = 1 << N;

int n, m;
LL f[N][M];
vector<int> state[M];
bool st[M];

int main()
{
    while (cin >> n >> m, n || m)
    {
        for (int i = 0; i < 1 << n; i ++ )
        {
            int cnt = 0;
            bool is_valid = true;
            for (int j = 0; j < n; j ++ )
                if (i >> j & 1)
                {
                    if (cnt & 1)
                    {
                        is_valid = false;
                        break;
                    }
                    cnt = 0;
                }
                else cnt ++ ;
            if (cnt & 1) is_valid = false;
            st[i] = is_valid;
        }

        for (int i = 0; i < 1 << n; i ++ )
        {
            state[i].clear();
            for (int j = 0; j < 1 << n; j ++ )
                if ((i & j) == 0 && st[i | j])
                    state[i].push_back(j);
        }

        memset(f, 0, sizeof f);
        f[0][0] = 1;
        for (int i = 1; i <= m; i ++ )
            for (int j = 0; j < 1 << n; j ++ )
                for (auto k : state[j])
                    f[i][j] += f[i - 1][k];

        cout << f[m][0] << endl;
    }

    return 0;
}

三、蓝桥杯十一届 植树

1. 问题描述

img

2. 问题解决

#include<bits/stdc++.h>
using namespace std;
const int N=35;
struct tree
{
    int x,y,r,s;
}; 
bool cross[N][N];

tree t[N];

int maxa,n;

vector<int> plant;

//判断是否相交 
bool judge(tree t1,tree t2)
{
    if(pow(t1.x-t2.x,2)+pow(t1.y-t2.y,2)>= pow(t1.r+t2.r,2)) 
    return false;//不相交 
    return true;//相交 
}

//i表示第i颗树,ans 表示第i颗树未决策时的面积 
void dfs(int i,int ans) 
{
    if(i==n)
    {
        if(ans>maxa) maxa=ans;
        return;
    }
    //判断第i颗树可不可以种
    for(auto j:plant)
    {
        if(judge(t[i],t[j]))
        {
      dfs(i+1,ans);
          return; 
    }
    } 
     
     //如果第i颗树可以种
     //种: 
      plant.push_back(i);
      dfs(i+1,ans+t[i].s);
      plant.pop_back();
      //不种:
      dfs(i+1,ans); 
      return;      
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>t[i].x>>t[i].y>>t[i].r;
        t[i].s=t[i].r*t[i].r;
    } 
    
    for(int i=1;i<n;i++)
    {
        cross[i][i]=true;
        //对称矩阵只用计算一半
        for(int j=0;j<i;j++) 
        {
            cross[i][j]= judge(t[i],t[j]);
            cross[j][i]=cross[i][j];
        }
    } 
    dfs(0,0);
    cout<<maxa;
    return 0;
    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue.js是一种流行的JavaScript框架,用于构建用户界面。要实现每日打卡功能,你可以按照以下步骤进行: 1. 创建一个Vue组件,用于显示打卡相关的信息和按钮。 2. 在组件的data属性中定义一个变量,用于记录打卡状态,比如isPunched。 3. 在组件的methods属性中定义一个方法,用于处理打卡逻辑。当用户点击打卡按钮时,该方法会被调用。 4. 在方法中,你可以使用JavaScript的Date对象获取当前日期,并将其与用户上次打卡的日期进行比较。如果日期不一致,表示用户需要进行打卡操作。 5. 如果需要保存用户的打卡记录,你可以使用浏览器的本地存储(localStorage)或者发送请求到服务器来保存数据。 下面是一个简单的示例代码: ```html <template> <div> <p v-if="isPunched">今日已打卡</p> <p v-else>今日未打卡</p> <button @click="punch">打卡</button> </div> </template> <script> export default { data() { return { isPunched: false }; }, methods: { punch() { const lastPunchDate = localStorage.getItem('lastPunchDate'); const currentDate = new Date().toLocaleDateString(); if (lastPunchDate !== currentDate) { // 执行打卡逻辑 // ... // 更新打卡状态和日期 this.isPunched = true; localStorage.setItem('lastPunchDate', currentDate); } } } }; </script> ``` 在上面的示例中,我们使用了Vue的条件渲染指令(v-if和v-else)来根据打卡状态显示不同的文本。当用户点击打卡按钮时,会调用punch方法进行打卡逻辑的处理。我们使用localStorage来保存用户的上次打卡日期,并在下次打卡时进行比较。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值