假日團隊賽32

A 迴文日期

題意:問給定日期之間某年某月某日是迴文的數量,例如20200202,

Code:枚舉

#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#include <string>
#include <cstdio>
#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
typedef pair<int,int> pii;
const ll mod = 1000000000 ;
const int INF=0x3f3f3f3f;
using namespace std;
const int mxn = 4e5+7 ;
ll n,t,m,k,l,r,prime[mxn],isprime[mxn],phi[mxn];
string str ;
int main()
{
    TLE;
    int date1, date2, ans = 0;
    cin >> date1 >> date2;
    for(int i = 1000; i <= 9999; i += 1)
    {
        int m = i % 100, d = i / 100;
        m = m % 10 * 10 + m / 10;
        d = d % 10 * 10 + d / 10;
        if(m < 1 || m > 12 ||d < 1 || d > 31) continue;
        if( (m == 4 or m == 6 or m == 9 or m == 11) && d > 30 ) continue;
        if(m == 2)
        {
            if(d > 29) continue;
            if(i % 4 or (i % 100 == 0 and i % 400))  if(d > 28) continue;
        }
        int date = i * 10000 + m * 100 + d;
        if(date >= date1 and date <= date2)
            ans += 1;
    }
    cout << ans;
    return 0;
}

 

D 買鉛筆

#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#include <string>
#include <cstdio>
#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
const ll mod = 1000000007 ;
const int INF=0x3f3f3f3f;
const int mxn = 1e6+7 ;
typedef pair<int,int> pii;
map<pair<ll,ll>,ll>mp;
string str,s1,s2;
bool vis[mxn] ;
ll t,n,m,k,l,r,prime[mxn],isprime[mxn],bit[mxn],phi[mxn];
int main()
{
    cin>>n;
    ll ans = INF ;
    for(int i=1;i<=3;i++)
    {
        cin>>k>>m;

        ans = min(ans , n%k==0?n/k*m:(n/k+1)*m );
    }
    cout<<ans<<endl;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章