orzorz

8.2万

Dearth
YoungJ
Ycary
Sma11fats0

menbinwan
Silvervale

Reminiscence

YzWait2-4YsZth

yxc的小迷弟
itdreaman
yuanheci

orzorz
2021-06-01 21:45
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 210;
int a[N],s[N];

int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
s[a[i]]++;
}
for(int i=0;i<n;i++){
if(s[a[i]]==1) puts("BeiJu");
else cout<<s[a[i]]-1<<endl;
}
return 0;
}


orzorz
2021-06-01 21:23
#include<iostream>
#include<algorithm>
#include<unordered_set>
using namespace std;

int f[11];

unordered_set<int> s;

int main(){
for(int i=0;i<=10;i++){
f[i]=1;
for(int j=i;j;j--)
f[i]*=j;
}

for(int i=1;i<1<<10;i++){
int sum=0;
for(int j=0;j<11;j++){
if(i>>j&1) sum+=f[j];
}
s.insert(sum);
}

int n;
while(cin>>n&&n>=0){
if(s.count(n)) puts("YES");
else puts("NO");
}

return 0;
}


orzorz
2021-06-01 21:01
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<string>

using namespace std;

int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

unordered_map<string,int> month_name={
{"January",1},
{"February",2},
{"March",3},
{"April",4},
{"May",5},
{"June",6},
{"July",7},
{"August",8},
{"September",9},
{"October",10},
{"November",11},
{"December",12}
};

string week_name[]={"Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday","Sunday"};

bool is_run(int y){
return (y%4==0&&y%100) || (y%400==0);
}

int count_days(int m,int y){
if(m==2) return month[m]+is_run(y);
return month[m];
}

int main(){
int d,m,y;
string str;
while(cin>>d>>str>>y){
m=month_name[str];
int t=0;
int td=1,tm=1,ty=1;
int cur_day=count_days(tm,ty);
while(td<d||tm<m||ty<y){
if(td<cur_day){
td++;
}else{
td=1;
if(tm<12){
tm++;
}else{
tm=1;
ty++;
}
cur_day=count_days(tm,ty);
}
t++;
}
cout<<week_name[t%7]<<endl;
}
return 0;
}


orzorz
2021-06-01 13:09
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N = 210;
int a[N],w[N][N],f[N][N];

int main(){
int n,k,m;
cin>>n>>k>>m;

for(int i=1;i<=m;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&w[i][j]);

memset(f,-0x3f,sizeof f);
f[1][0]=0;
for(int i=2;i<=m;i++){
for(int j=0;j<=k;j++){
for(int s=1;s<i;s++){
if(j>=i-s-1)
f[i][j]=max(f[i][j],f[s][j-(i-s-1)]+w[a[s]][a[i]]);
}
}
}

int res=0;
for(int i=0;i<=k;i++)
res=max(res,f[m][i]);
cout<<res;
return 0;
}


orzorz
2021-05-30 11:48
#include<iostream>

using namespace std;

const int N = 1e5+10;
typedef long long LL;
int a[N],b[N];

int main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
LL sum=0;
for(int i=1;i<=n;i++)
if(b[i]) sum+=a[i];
LL maxs=0,s=0;
for(int i=1;i<=n;i++){
if(!b[i]) s+=a[i];
if(i>k&&!b[i-k]) s-=a[i-k];
maxs=max(maxs,s);
}

cout<<sum+maxs;
return 0;
}


orzorz
2021-05-30 10:50
#include<iostream>
#include<algorithm>
using namespace std;

const int N=1e5*31+10,M=1e5+10;
int son[N][2],cnt[N],a[M],idx;

void insert(int x,int t){
int p=0;
for(int i=30;i>=0;i--){
int u=x>>i&1;
if(!son[p][u]) son[p][u]=++idx;
p=son[p][u];
cnt[p]+=t;
}
}

int query(int x){
int res=0,p=0;
for(int i=30;i>=0;i--){
int u=x>>i&1;
if(cnt[son[p][!u]]){
p=son[p][!u];
res=2*res+1;
}else{
p=son[p][u];
res*=2;
}
}
return res;
}

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

insert(a[0],1);//这是一个对边界的处理，这样把后面第i-m-1=0时的元素删除的时候不用特判了
int res=0;
for(int i=1;i<=n;i++){
if(i>m) insert(a[i-m-1],-1);
res=max(res,query(a[i]));
insert(a[i],1);
}

cout<<res;

return 0;
}


orzorz
2021-04-17 17:29

## 版本一

class Solution {
public:
bool canJump(vector<int>& nums) {
int n=nums.size();
vector<bool> f(n);
f[0]=true;
for(int i=1,j=0;i<n;i++){
while(j+nums[j]<i) j++;
if(f[j]) f[i]=true;
}
return f[n-1];

}
};


## 版本二

class Solution {
public:
bool canJump(vector<int>& nums) {
for(int i=0,j=0;i<nums.size();i++){
if(j<i) return false;//每次进行判断，看看j是否可以跳到i处
j=max(j,i+nums[i]);
}
return true;
}
};


orzorz
2021-04-17 17:11
class Solution {
public:
vector<int> spiralOrder(vector<vector<int>>& matrix) {
int n=matrix.size(),m=matrix[0].size();
vector<int> res;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
vector<vector<bool>> st(n,vector<bool>(m));
for(int i=0,x=0,y=0,dir=0;i<n*m;i++){
st[x][y]=true;
res.push_back(matrix[x][y]);
int a=x+dx[dir],b=y+dy[dir];
if(a<0||a>=n||b<0||b>=m||st[a][b]){
dir=(dir+1)%4;
a=x+dx[dir],b=y+dy[dir];
}
x=a;y=b;
}
return res;
}
};


orzorz
2021-04-17 16:59

## 动态规划

class Solution {
public:
int maxSubArray(vector<int>& nums) {
int res=INT_MIN;
for(int i=0,last=0;i<nums.size();i++){
last=max(0,last)+nums[i];
res=max(res,last);
}
return res;
}
};


## 分治法

orzorz
2021-04-17 16:24
class Solution {
public:
int n;
int ans;
vector<bool> col,dg,udg;

int totalNQueens(int _n) {
n=_n;
col=vector<bool>(n);
dg=udg=vector<bool>(2*n);
dfs(0);
return ans;
}

void dfs(int u){
if(u==n){
ans++;
return;
}
for(int i=0;i<n;i++){
if(!col[i]&&!dg[u+i]&&!udg[u-i+n]){
col[i]=dg[u+i]=udg[u-i+n]=true;
dfs(u+1);
col[i]=dg[u+i]=udg[u-i+n]=false;
}
}
}
};