WNx

3354

jifanxi
limie
Pipipapi

icebreaker
105度

xjc008

BestAc
ky_li

captainDDL
chtld
wa的一声哭出来

WNx
6天前

WNx
4个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 10000010;
int a[N];

void Qsort(int l, int r, int a[]){
if(l >= r) return ;

int i = l - 1, j = r + 1, mid;
mid = a[(l + r) >> 1];

while(i < j){
while(a[++ i] < mid) ;
while(a[-- j] > mid) ;
if(i < j) swap(a[i], a[j]);
}

Qsort(l, j, a);
Qsort(j + 1, r, a);
}

int main(){
int n;
cin >> n;
for(int i = 0; i < n; i ++) cin >> a[i];
Qsort(0, n - 1, a);
for(int i = 0; i < n; i ++) cout << a[i] << ' ';
return 0;
}



WNx
4个月前
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/

class Solution {
public:
int pathSum(TreeNode* root){
int sum = 0;
res(root, 0, sum);
return sum;
}

int res(TreeNode* p, int d){
if(p){
res(p->left, d + 1, sum);
res(p->right, d + 1, sum);
if(p->right == NULL && p->left == NULL)
}
}
};


WNx
2020-06-16 10:42
#include <iostream>

using namespace std;

int n, m = 0;
const int N = 10;
// bool st[N];
int path[N];

void dfs(int u)
{
if(u == n){
for(int i=0;i<n;i++) printf("%d ", path[i]);
putchar('\n');
return;
}
for(int i=1;i<=n;i++){
if(!((m >> i) & 1)){
path[u] = i;
m = m | 1 << i;
dfs(u+1);
m = m ^ 1 << i;
path[u] = 0;
}
}
}

int main(void)
{
cin >> n;
dfs(0);
return 0;
}


WNx
2020-06-16 10:23
#include <iostream>
using namespace std;
int n;
const int N = 20;
bool dg[N], udg[N], st[N];
char g[N][N];

void dfs(int u)
{
if(u == n){
for(int i=0;i<n;i++){
puts(g[i]);
}
puts("");
return;
}
for(int i=0;i<n;i++){
if(!st[i] && !dg[i+u] && !udg[u-i+n]){
g[u][i] = 'Q';
st[i] = dg[i+u] = udg[u-i+n] = true;
dfs(u+1);
st[i] = dg[i+u] = udg[u-i+n] = false;
g[u][i] = '.';
}
}
}

int main(void)
{
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) g[i][j] = '.';
}
dfs(0);
return 0;
}


WNx
2020-06-08 17:47
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], s[N];

int main(void)
{
int n, m;
cin >> n >> m;
for(int i=1;i<=n;i++) scanf("%d", &a[i]);

for(int i=1;i<=n;i++) s[i] = s[i-1] + a[i];

while(m--){
int l, r;
cin >> l >> r;
cout << s[r] - s[l-1] << endl;
}
return 0;
}


WNx
2020-06-08 16:34
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector<pair<int, int>> segs;

void merge(vector<pair<int, int>> &segs)
{
sort(segs.begin(), segs.end());
int st = -2e9, ed = -2e9;
vector<pair<int, int>> res;
for(auto seg : segs){
if(ed < seg.first){
if(st != -2e9) res.push_back({st, ed});
st = seg.first, ed = seg.second;
}
else ed = max(ed, seg.second);
}
if(st != -2e9) res.push_back({st, ed});

segs = res;
}

int main(void)
{
int n;
cin >> n;
for(int i=0;i<n;i++){
int l, r;
cin >> l >> r;
segs.push_back({l, r});
}

merge(segs);

cout << segs.size();
return 0;
}


WNx
2020-06-08 15:31
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 300010;
int a[N], s[N];
typedef pair<int, int> PII;
vector<int> alls;

int find(int x)
{
int l = 0, r = alls.size() - 1;
while(l < r){
int mid = l + r >> 1;
if(x <= alls[mid]) r = mid;
else l = mid + 1;
}
return r + 1;
}

int main(void)
{
int n, m;
cin >> n >> m;
for(int i=0;i<n;i++){
int x, c;
cin >> x >> c;
alls.push_back(x);
}
for(int i=0;i<m;i++){
int l, r;
cin >> l >> r;
query.push_back({l, r});
alls.push_back(l);
alls.push_back(r);
}
sort(alls.begin(), alls.end());
alls.erase(unique(alls.begin(), alls.end()), alls.end());

int x = find(item.first);
a[x] += item.second;
}

for(int i=1;i<=alls.size();i++) s[i] = s[i-1] + a[i];

for(auto item : query){
int l = find(item.first), r = find(item.second);
cout << s[r] - s[l-1] << endl;
}

return 0;
}


WNx
2020-06-07 19:46
class Solution {
public:
bool isPalindrome(int x) {
bool m = true;
if(x < 0) return false;
string str;
str = to_string(x);
for(int i=0; i<str.size()/2; i++){
if(str[i] != str[str.size() - i - 1]) m = false;
}
return m;
}
};


WNx
2020-06-07 19:45
int lengthOfLongestSubstring(char * s){
int i,j=0,count=0,max=0,index[128]={0},start=0;

for(i=0;s[i]!='\0';i++){
if(index[s[i]]>start){
count=i-start;
if(count>max) max=count;
start=index[s[i]];
}
index[s[i]]=i+1;
}

count=i-start;
return max>count?max:count;
}