标签:www continue line == while clu red ring char
奇数或者\(2\)是\(NO\)
#include<bits/stdc++.h>
using namespace std;
namespace red{
inline int read()
{
int x=0;char ch,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-')f=0,ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
int n;
inline void main()
{
n=read();
if(n&1||n==2) puts("NO");
else puts("YES");
}
}
signed main()
{
red::main();
return 0;
}
先都给最少的,然后从前往后加就行了
#include<bits/stdc++.h>
using namespace std;
namespace red{
inline int read()
{
int x=0;char ch,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-')f=0,ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
const int N=50;
int n,sum;
int a[N],b[N],c[N];
inline void main()
{
n=read(),sum=read();
for(int i=1;i<=n;++i)
{
a[i]=read(),b[i]=read();
}
for(int i=1;i<=n;++i)
{
c[i]=a[i],sum-=a[i];
}
if(sum<0)
{
puts("NO");
return;
}
for(int i=1;i<=n&∑++i)
{
c[i]+=min(sum,b[i]-a[i]);
sum-=min(sum,b[i]-a[i]);
}
if(sum)
{
puts("NO");
return;
}
puts("YES");
for(int i=1;i<=n;++i) printf("%d ",c[i]);
}
}
signed main()
{
red::main();
return 0;
}
\(map\)
#include<bits/stdc++.h>
using namespace std;
namespace red{
inline int read()
{
int x=0;char ch,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-')f=0,ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
int n;
map<string,int> q;
string s;
char t[110];
int st[100],top,l;
inline void main()
{
n=read();
for(int i=1;i<=n;++i)
{
cin>>s;
if(!q[s])
{
q[s]=1;
puts("OK");
}
else
{
int tmp=q[s];
++q[s];
memset(t,0,sizeof(t));
while(tmp) st[++top]=tmp%10,tmp/=10;
l=0;
while(top) t[l++]=st[top--]+'0';
cout<<s<<t<<endl;
}
}
}
}
signed main()
{
red::main();
return 0;
}
按\(w\)排序以后就是裸的最长严格上升子序列了……
\(n\le 5000\)显然可以直接暴力,然而我还是写了线段树优化……
注意严格上升,当\(w\)与上一位不同时再把上一位\(w\)值加进线段树
#include<bits/stdc++.h>
using namespace std;
namespace red{
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
#define mid ((l+r)>>1)
inline int read()
{
int x=0;char ch,f=1;
for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
if(ch=='-')f=0,ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
}
const int N=1e6+10;
int aa,bb,tot,n,m,pre;
int f[N],g[N];
int ret,w;
int st[N],top;
struct node
{
int x,y,id;
inline bool operator < (const node &t) const
{
return x<t.x;
}
}a[N];
int ans[N<<2],pos[N<<2];
inline void update(int d,int l,int r,int p,int k,int w)
{
if(l==r)
{
if(k>ans[p])
{
ans[p]=k;
pos[p]=w;
}
return;
}
if(d<=mid) update(d,l,mid,ls(p),k,w);
else update(d,mid+1,r,rs(p),k,w);
ans[p]=max(ans[ls(p)],ans[rs(p)]);
pos[p]=ans[ls(p)]>=ans[rs(p)]?pos[ls(p)]:pos[rs(p)];
}
inline node query(int tl,int tr,int l,int r,int p)
{
if(!tr) return (node){0,0};
if(tl<=l&&r<=tr) return (node){ans[p],pos[p]};
if(tr<=mid) return query(tl,tr,l,mid,ls(p));
if(tl>mid) return query(tl,tr,mid+1,r,rs(p));
node tx=query(tl,tr,l,mid,ls(p)),ty=query(tl,tr,mid+1,r,rs(p));
return tx.x>=ty.x?tx:ty;
}
inline void main()
{
tot=read(),aa=read(),bb=read();
for(int x,y,i=1;i<=tot;++i)
{
x=read(),y=read();
if(x<=aa||y<=bb) continue;
a[++n].x=x,a[n].y=y,a[n].id=i;
m=max(m,a[n].y);
}
if(!n)
{
puts("0");
return;
}
sort(a+1,a+n+1);
pre=1;
for(int i=1;i<=n;++i)
{
if(a[i].x^a[i-1].x)
{
for(int j=pre;j<=i-1;++j) update(a[j].y,1,m,1,f[j],j);
pre=i;
}
node t=query(1,a[i].y-1,1,m,1);
f[i]=f[t.y]+1;
g[i]=t.y;
if(f[i]>ret) ret=f[i],w=i;
}
printf("%d\n",ret);
while(w) st[++top]=a[w].id,w=g[w];
while(top) printf("%d ",st[top--]);
}
}
signed main()
{
red::main();
return 0;
}
标签:www continue line == while clu red ring char
原文地址:https://www.cnblogs.com/knife-rose/p/12232357.html