1. 程式人生 > 實用技巧 >2020.10.09個人賽

2020.10.09個人賽

題目:High School: Become Human

思路:

這道題就是問一下xy ,與 yx的大小關係,看完資料,這個肯定是不能直接算的,所以肯定是要同時取對數,將次數放下來,這樣就很好比較了,我做這道題時,腦門一熱,自以為是的認為只有 x = y時才會相等,忘記了 24=42,菜雞落淚。

解題程式碼:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include 
<map> #include <set> using namespace std; const long long N = 1e10 + 7; const int maxn = 2e5 + 5; const long long INF = 8e18; typedef long long ll; #define for0(i,n) for(int i = 0;i < n;i++) #define for1(i,n) for(int i = 1;i <= n;i++) map<string,int>ma; int main() { ll x,y; cin
>> x >> y; if(x == y) cout << "=" << endl; else{ if(y * log(x) > x * log(y)) cout << ">" << endl; else if(y * log(x) < x * log(y)) cout << "<" << endl; else cout
<< "=" << endl; } return 0; }

題目:Three displays

思路:

這道題就是找三個物品,編號 i<j<k ,並且三者的花費符合 ci < cj < ck,問最小花費,若不存在輸出-1,這個通過遍歷中間位置來更新最小花費,向前找小於它的,向後找大於它的,維護最小值就行。

解題程式碼:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
using namespace std;
const long long N = 1e10 + 7;
const int maxn = 2e5 + 5;
const long long INF = 8e18;
typedef long long ll;
#define for0(i,n) for(int i = 0;i < n;i++)
#define for1(i,n) for(int i = 1;i <= n;i++)
struct p{
    int s;
    ll c;
}pp[3010];

int main()
{
    ios::sync_with_stdio(false);
    ll minnum = INF;
    int n,sign = 0;
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> pp[i].s;
    for(int i = 0;i < n;i++)
        cin >> pp[i].c;
    int sign1,sign2;
    for(int i = 1;i < n-1;i++){
        ll num = pp[i].c;
        sign1 = 0,sign2 = 0;
        ll tempmin1 = INF;
        ll tempmin2 = INF;
        for(int j = 0;j < i;j++){
            if(pp[j].s < pp[i].s){
                tempmin1 = min(tempmin1,pp[j].c);
                sign1 = 1;
            }

        }
        for(int j = i+1;j < n;j++){
            if(pp[j].s > pp[i].s){
                tempmin2 = min(tempmin2,pp[j].c);
                sign2 = 1;
            }

        }
        if(sign1 && sign2){
            sign = 1;
            num += tempmin1;
            num += tempmin2;
            minnum = min(minnum,num);
        }
       
    }
    
    if(sign)
        cout << minnum << endl;
    else
        cout << -1 << endl;

    return 0;
}