T1

\(solution\)

求出第一个开始下降的位置,移动到连续的与它相同的数的最前面的一个数的位置,记录为\(p\)

\(p\)以前的位置的数与原数相同,\(p\)位置为原数-1,后面全部为9

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; const int MAXN=200010; int n,a[MAXN],ans[MAXN];
char s[MAXN]; int main()
{
freopen("increase.in","r",stdin);
freopen("increase.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;++i)
a[i]=s[i]-'0';
int pos=n+1;
for(int i=1;i<n;++i)
if(a[i]>a[i+1]){
pos=i;
break;
}
if(pos<n)
while(pos>1&&a[pos-1]==a[pos]) --pos;
for(int i=1;i<=n;++i){
if(i<pos) ans[i]=a[i];
else if(i==pos) ans[i]=a[i]-1;
else ans[i]=9;
}
int i=1;
while(ans[i]==0&&i<n) ++i;
for(;i<=n;++i)
printf("%d",ans[i]);
puts("");
fclose(stdin); fclose(stdout);
return 0;
}

T2

\(solution\)

考虑每一对逆序对的贡献为$a[i] \times a[j] \times i \times (n-j+1) $

用树状数组维护满足a[i]>a[j]的$ \sum{ a[j] \times (n-j+1)} $即可

也可以在归并排序时记录一个后缀和处理

需要龟速乘法防止爆long long

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std; const int MAXN=100010;
const int MOD=1000000000007ll; inline int read(){
int x=0,f=1; char c=getchar();
while(c<'0'){ if(c=='-') f=-1; c=getchar(); }
while(c>='0') x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
} inline int mul(int x,int y){
int s=0ll;
while(y){
if(y&1) s=(s+x)%MOD;
y>>=1ll;
x=(x+x)%MOD;
}
return s;
} int n,Ans;
struct Data{
int v,id,nv;
} a[MAXN]; inline bool cmp1(Data x,Data y){
return x.v<y.v;
} inline bool cmp2(Data x,Data y){
return x.id<y.id;
} int tree[MAXN];
inline int lowbit(int x){ return x&(-x); }
inline int query(int x){
int ans=0;
for(;x;x-=lowbit(x))
ans=(ans+tree[x])%MOD;
return ans;
}
inline void update(int x,int d){
for(;x<=n;x+=lowbit(x))
tree[x]=(tree[x]+d)%MOD;
} signed main()
{
freopen("multiplication.in","r",stdin);
freopen("multiplication.out","w",stdout);
scanf("%lld",&n);
if(n<=1000){
for(int i=1;i<=n;++i)
a[i].v=read();
int tmp1,tmp2;
for(int i=1;i<n;++i)
for(int j=i+1;j<=n;++j)
if(a[i].v>a[j].v){
tmp1=mul(a[i].v,a[j].v);
tmp2=mul(i,n-j+1);
Ans=(Ans+mul(tmp1,tmp2))%MOD;
}
printf("%lld\n",(Ans+MOD)%MOD);
}
else{
for(int i=1;i<=n;++i)
a[i].v=read(),a[i].id=i;
sort(a+1,a+1+n,cmp1);
int cnt=0; a[0].v=-1;
for(int i=1;i<=n;++i)
a[i].nv=(a[i].v==a[i-1].v)?cnt:++cnt;
sort(a+1,a+1+n,cmp2);
for(int i=n;i>=1;--i){
Ans=(Ans+mul(mul(a[i].v,i),query(a[i].nv-1)))%MOD;
int d=mul(a[i].v,n-i+1);
update(a[i].nv,d);
}
printf("%lld\n",(Ans+MOD)%MOD);
}
fclose(stdin); fclose(stdout);
return 0;
}
/*
5
3 2 1 5 4
125
6
1000 2 400 6 1 400
9
100000 23333 19260817 19491001 2897370649 1 32 114514 1919810
78834965239
*/

T3

\(solution1\)

先检查各个小正方形的面积和是否等于大正方形,

之后只要满足不重叠就可以了

扫描线线段树维护,在区间加入覆盖标记前判断是否已经被覆盖

\(solution2\)

先检查面积,再判重叠

考察一个图中的每一个点,不难发现,以每个点为原点,每个点的四个象限都必须有且只有一个矩形覆盖

于是对每个点维护四个标记,对于边、角特殊处理,每个矩形的对四个角上的点的对应象限打标记即可

简化:内部的一个点只能成为2个或4个矩形的顶点,直接记录判断即可

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> using namespace std; #define INF 2147483647
#define maxn 100010 int n,rectangles[maxn][4]; struct point
{
int x,y,d;
point(){}
point(int a,int b,int c)
{
x=a;y=b;d=c;
}
}p[maxn<<2],q[maxn<<2]; bool operator<(const point &a,const point &b)
{
if (a.x!=b.x) return a.x<b.x;
return a.y<b.y;
} bool cmp(const point &a,const point &b)
{
if (a.y!=b.y) return a.y<b.y;
return a.x<b.x;
} struct line
{
int x,y,l,r,d;
line(){}
line(int a,int b,int c,int e)
{
x=a;y=a;l=b;r=c;d=e;
}
}vert[maxn<<2],hori[maxn<<2]; bool operator<(const line &a,const line &b)
{
if (a.x!=b.x) return a.x<b.x;
if (a.l!=b.l) return a.l<b.l;
return a.r<b.r;
} bool isRectangleCover() {
int minx=INF,maxx=-INF,miny=INF,maxy=-INF;
for (int a=0;a<n;a++)
{
minx = min(minx,rectangles[a][0]);
maxx = max(maxx,rectangles[a][2]);
miny = min(miny,rectangles[a][1]);
maxy = max(maxy,rectangles[a][3]);
}
long long s=(0ll+maxx-minx)*(0ll+maxy-miny);
for (int a=0;a<n;a++)
s -= (0ll+rectangles[a][2]-rectangles[a][0])*(0ll+rectangles[a][3]-rectangles[a][1]);
if (s) return false;
int m=0,n1=0,n2=0;
for (int a=0;a<n;a++)
{
p[++m]=point(rectangles[a][0],rectangles[a][1],1);
p[++m]=point(rectangles[a][2],rectangles[a][1],2);
p[++m]=point(rectangles[a][2],rectangles[a][3],4);
p[++m]=point(rectangles[a][0],rectangles[a][3],8);
vert[++n1]=line(rectangles[a][1],rectangles[a][0],rectangles[a][2],3);
vert[++n1]=line(rectangles[a][3],rectangles[a][0],rectangles[a][2],12);
hori[++n2]=line(rectangles[a][0],rectangles[a][1],rectangles[a][3],9);
hori[++n2]=line(rectangles[a][2],rectangles[a][1],rectangles[a][3],6);
}
sort(p+1,p+m+1);
sort(vert+1,vert+n1+1);
sort(hori+1,hori+n2+1);
int k=0;
for (int a=1;a<=m;)
{
int b=a+1,s=p[a].d,x=p[a].x,y=p[a].y;
while (b<=m && p[b].x==x && p[b].y==y)
{
if (s&p[b].d) return false;
s|=p[b].d;
b++;
} int news=0;
if (x==minx) news|=6;
if (x==maxx) news|=9;
if (y==miny) news|=12;
if (y==maxy) news|=3;
if (news&s) return false;
s|=news;
q[++k] = point(x,y,s); a=b;
}
sort(q+1,q+k+1);
for (int a=1;a<=n2;a++)
{
int x=hori[a].x,y1=hori[a].l,y2=hori[a].r,s=hori[a].d;
int l=0,r=k;
while (l+1!=r)
{
int m=(l+r)>>1;
if (q[m].x>x || (q[m].x==x && q[m].y>y1)) r=m;
else l=m;
}
while (r<=k && q[r].x==x && q[r].y<y2)
{
if (q[r].d&s) return false;
q[r].d|=s;
r++;
}
} sort(q+1,q+k+1,cmp);
for (int a=1;a<=n1;a++)
{
int y=vert[a].y,x1=vert[a].l,x2=vert[a].r,s=vert[a].d;
int l=0,r=k;
while (l+1!=r)
{
int m=(l+r)>>1;
if (q[m].y>y || (q[m].y==y && q[m].x>x1)) r=m;
else l=m;
}
while (r<=k && q[r].y==y && q[r].x<x2)
{
if (q[r].d&s) return false;
q[r].d|=s;
r++;
}
}
return true; /*int l=0,r=n1;
while (l+1!=r)
{
int m=(l+r)>>1;
if (vert[m].y >= y) r=m;
else l=m;
}
while (r<=n1 && vert[r].y==y)
{
if (x>vert[r].l && x<vert[r].r)
{
if (s&vert[r].d) return false;
s|=vert[r].d;
}
r++;
}
l=0,r=n2;
while (l+1!=r)
{
int m=(l+r)>>1;
if (hori[m].x >= x) r=m;
else l=m;
}
while (r<=n1 && hori[r].x==x)
{
if (y>hori[r].l && y<hori[r].r)
{
if (s&hori[r].d) return false;
s|=hori[r].d;
}
r++;
}
if (s!=15) return false;*/
return true;
} int main()
{
int t;
scanf("%d",&t);
for (;t--;)
{
scanf("%d",&n);
for (int a=0;a<n;a++)
for (int b=0;b<4;b++)
scanf("%d",&rectangles[a][b]);
if (isRectangleCover()) printf("Perfect\n");
else printf("Guguwansui\n");
} return 0;
}

2019qbxtCSP-S2 模拟题1的更多相关文章

  1. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  2. URAL 2046 A - The First Day at School 模拟题

    A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  3. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  4. ACdreamoj(1105)模拟题

    题意:射一次激光最多能够攻击到几个敌人(因为激光非常强大,能够在击中敌人后穿过它,而瑶瑶自己的坦克因为有特殊装置,所以不会被激光击中.激光也会直接穿过它) . 表示此处为空地 * 表示此处为障碍(激光 ...

  5. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  6. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  7. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  8. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  9. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  10. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. [JAVA] 日常填坑 java.lang.SecurityException: Prohibited package name: java.xxx

    java虚拟机不允许包名以java开头. https://blog.csdn.net/sinat_28690417/article/details/72328547

  2. python调用MySQL数据库

    在Python中访问mysql数据库中的数据需要三步骤: 1,建立连接 2,操作数据库 3,连接关闭

  3. Python的设计哲学--zen of Python

               Python的设计哲学--zen of Python Beautiful is better than ugly. 优美胜于丑陋 Explicit is better than ...

  4. What are regsvr32, regasm and gacutil using for?(转载)

    What are regsvr32, regasm and gacutil using for? Regasm.exe is used to create COM Callable Wrapper ( ...

  5. Oracle的创建表空间及用户

    学习笔记: 1.创建表空间 --创建表空间 create tablespace thepathofgrace datafile 'c:\thepathofgrace.dbf' size 100m au ...

  6. 小程序上传图片功能 uploadFile:fail Read error:ssl=0xa738d808:I/O error during system call,Connection reset by peer

    由于纯网页上传图片小程序会闪退,就采用了小程序原生的上传功能wx.uploadfile 处理流程: 1.网页需要跳转到小程序 需要引用 <script src='https://res.wx.q ...

  7. 如何简单使用tensorboard展示(一)

    我使用tensorboard中的graph做了展示,至于其它功能可以类推,其代码如下: import numpy as npimport tensorflow as tf x_img = np.arr ...

  8. Python学习笔记之json.dump和json.load

    10-11 喜欢的数字:编写一个程序,提示用户输入他喜欢的数字,并使用json.dump()将这个数字存储到文件中.再编写一个程序,从文件中读取这个值,并打印消息“I know your favori ...

  9. lumen 响应宏

    响应宏 laravel 中的响应宏,说明文档中有,lumen的没有找到.于是参考laravel 项目中的响应宏写了个Lumen的 1. 新建文件 App\Providers\ResponseMacro ...

  10. ajax+vue简单使用

    <script type="text/javascript" src="http://cdn.bootcss.com/vue/2.2.2/vue.min.js&qu ...