头像

Value

Personal


访客:2497

离线:59分钟前



Value
2小时前
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1010;
int heap[N];
int n, m;
void print(int t){
    if(t * 2 <= m)  print(t * 2);
    if(t * 2 + 1 <= m)  print(t * 2 + 1);
    if(t <= m)  cout << heap[t];
    if(t == 1)  cout << endl;     //  控制一下格式输出
    else    cout << " ";
}
bool isMin_heap(){
    for(int i = m / 2; i; i -- ){
        if(i * 2 <= m && heap[i] > heap[i * 2]) return false;
        if(i * 2 + 1 <= m && heap[i] > heap[i * 2 + 1]) return false;
    }
    return true;
}
bool isMax_heap(){
    for(int i = m / 2; i; i -- ){
        if(i * 2 <= m && heap[i] < heap[i * 2]) return false;
        if(i * 2 + 1 <= m && heap[i] < heap[i * 2 + 1]) return false;
    }
    return true;
}
int main(){
    cin >> n >> m;
    while(n -- ){
        for(int i = 1; i <= m; i ++ )   scanf("%d", &heap[i]);
        if(isMin_heap()) cout << "Min Heap" << endl;
        else if(isMax_heap())    cout << "Max Heap" << endl;
        else    cout << "Not Heap" << endl;
        print(1);
    }
    return 0;
}



Value
14小时前
class Solution {
public:
    int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts) {
        horizontalCuts.push_back(0), horizontalCuts.push_back(h);
        verticalCuts.push_back(0), verticalCuts.push_back(w);
        sort(horizontalCuts.begin(), horizontalCuts.end());
        sort(verticalCuts.begin(), verticalCuts.end());
        typedef long long ll;
        ll hmax, vmax;
        hmax = vmax = 0;
        ll MOD = 1E9 + 7;
        int hsize = horizontalCuts.size();
        int vsize = verticalCuts.size();
        for(int i = 1; i < hsize; i ++ ){
            hmax = max(hmax, ll(horizontalCuts[i] - horizontalCuts[i - 1]));
        }
        for(int i = 1; i < vsize; i ++ ){
            vmax = max(vmax, ll(verticalCuts[i] - verticalCuts[i - 1]));
        }
        return hmax * vmax % MOD;
    }
};



Value
14小时前
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        int len = nums.size();
        int res = 0;
        for(int i = 0; i < len; i ++ ){
            for(int j = i + 1; j < len; j ++ ){
                res = max(res, (nums[i] - 1) * (nums[j] - 1));
            }
        }
        return res;
    }
};



Value
14小时前
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 30010;
struct node{
    string id;
    int score;
    int final_rank, location_number, local_rank;
    void toString(){
        cout << id << " " << final_rank << " " << location_number << " " << local_rank << endl;
    }
};
node stu[N], tmp[N];
int way;
bool cmp(node a, node b){
    if(a.score != b.score)  return a.score > b.score;
    else    return a.id < b.id;
}
int main(){
    int region;
    cin >> region;
    int n, cnt;
    cnt = 0;
    for(int i = 1; i <= region; i ++ ){
        cin >> n;
        for(int j = 0; j < n; j ++ ){
            cin >> tmp[j].id >> tmp[j].score;;
            tmp[j].location_number = i;
        }
        sort(tmp, tmp + n, cmp);
        for(int j = 0; j < n; j ++ ){
            if(!j || tmp[j].score != tmp[j - 1].score)  tmp[j].local_rank = j + 1;
            else    tmp[j].local_rank = tmp[j - 1].local_rank;
            stu[cnt ++ ] = tmp[j];
        }
    }
    sort(stu, stu + cnt, cmp);
    for(int i = 0; i < cnt; i ++ ){
        if(!i || stu[i].score != stu[i - 1].score)  stu[i].final_rank = i + 1;
        else    stu[i].final_rank = stu[i - 1].final_rank;
    }
    cout << cnt << endl;
    for(int i = 0; i < cnt ; i ++ ) stu[i].toString();
    return 0;
}



Value
14小时前
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 4E5 + 10;
int a[N];
int main(){
    int n, m;
    cin >> n;
    for(int i = 0; i < n; i ++ )    scanf("%d", &a[i]);
    cin >> m;
    for(int i = n; i < m + n; i ++ ) scanf("%d", &a[i]);
    sort(a, a + n + m);
    cout << a[m + n - 1 >> 1] << endl;
    return 0;
}



Value
14小时前
#include <iostream>
#include <unordered_map>
#include <vector>
#include <cstdio>
using namespace std;
unordered_map<char, char> change;
void init(){
    change['1'] = '@';  change['0'] = '%';
    change['l'] = 'L';  change['O'] = 'o';
}
typedef pair<string, string> pii;
vector<pii> res;
int main(){
    init();
    int n;
    cin >> n;
    string user, pwd;
    bool flag;
    for(int i = 0; i < n; i ++ ){
        cin >> user >> pwd;
        flag = false;
        for(int i = 0; i < pwd.size(); i ++ ){
            if(change.find(pwd[i]) != change.end()){
                pwd[i] = change[pwd[i]];
                flag = true;
            }
        }
        if(flag)    res.push_back({user, pwd});
    }
    if(res.size() == 0){
        if(n == 1)  printf("There is %d account and no account is modified\n", n);
        else    printf("There are %d accounts and no account is modified\n", n);
    }else{
        cout << res.size() << endl;
        for(auto it : res)  cout << it.first << " " << it.second << endl;
    }
    return 0;
}



Value
15小时前
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1E5 + 10;
int s[N];
int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ )   scanf("%d", &s[i]);
    for(int i = 1; i <= n; i ++ )   s[i] += s[i - 1];
    int i, j;
    i = j = 1;;
    int vmin = 0x3f3f3f;
    while(i <= j && j <= n){
        int value = s[j] - s[i - 1];
        if(value < m || j == i)   j ++ ;          
        else{
            vmin = min(vmin, value - m);
            i ++ ;
        }
    }
    i = j = 1;
    while(i <= j && j <= n){
        int value = s[j] - s[i - 1];
        if(value - m == vmin)   cout << i << "-" << j << endl; 
        if(value <= m || j == i)   j ++ ;
        else    i ++ ;
    }
    return 0;
}



Value
1天前
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
vector<pii> res;
int main(){
    int n;
    cin >> n;
    cout << n << "=";
    bool flag = false;
    for(int i = 2; i <= n / i; i ++ ){
        if(n % i == 0){
            int s = 0;
            while(n % i == 0){
                s ++ ;
                n /= i;
            }
            res.push_back({i, s});
            flag = true;
        }
    }
    if(n > 1)  res.push_back({n, 1}), flag = true;
    if(!flag)   res.push_back({n, 1});      //  特判1
    flag = true;
    for(int i = 0; i < res.size(); i ++ ){
        if(!flag)    cout << "*";
        flag = false;
        cout << res[i].first;
        if(res[i].second != 1)  cout << "^" << res[i].second;
    }
    return 0;
}



Value
1天前
#include <iostream>
#include <unordered_map>
using namespace std;
unordered_map<string, int> mp;
const int N = 1E4 + 10;
bool prime[N];
void init(){
    for(int i = 2; i < N; i ++ ){
        if(!prime[i])   for(int k = i * i; k < N; k += i )    prime[k] = true;
    }
}
int main(){
    init();
    int n;
    cin >> n;
    string sno;
    for(int i = 1; i <= n; i ++ ){
        cin >> sno;
        mp[sno] = i;
    }
    cin >> n;
    while(n -- ){
        cin >> sno;
        cout << sno << ": ";
        if(mp.find(sno) == mp.end())    cout << "Are you kidding?";
        else{
            if(mp[sno] == -1)    cout << "Checked";
            else if(mp[sno] == 1)   cout << "Mystery Award";
            else if(!prime[mp[sno]])    cout << "Minion";
            else    cout << "Chocolate";
            mp[sno] = -1;
        }
        if(n)   cout << endl;
    } 
}



Value
1天前
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
const int N = 4E4 + 10;
unordered_map<string, int> mp;   //  建立索引
vector<vector<int>> course(N);   //  学生的课表
int id = 0;
int main(){
    int n, k;
    cin >> n >> k;
    int cno, num;
    string name;
    while(k -- ){
        cin >> cno >> num;
        while(num -- ){
            cin >> name;
            if(mp.find(name) == mp.end())   mp[name] = id ++ ;
            course[mp[name]].push_back(cno);
        }
    }
    while(n -- ){
        cin >> name;
        cout << name << " ";
        if(mp.find(name) == mp.end())   cout << "0" << endl;
        else{
            int sno = mp[name];
            cout << course[sno].size() << " ";
            sort(course[sno].begin(), course[sno].end());
            for(int i = 0; i < course[sno].size(); i ++ ){
                cout << course[sno][i];
                if(i == course[sno].size() - 1) cout << endl;
                else    cout << " "; 
            }
        }
    }
    return 0;
}

其实可以直接

unordered_map<string, <vector<int>>