Codeforces Round #149 (Div. 2)【AK】

吐槽:比赛刚开始codeblocks出了点问题。。边看题边弄编译器。。。囧。。

    D居然一直没看。。因为E题意好懂。。然后sb地卡了一场E。。。战斗力太不稳定。。。

A...

A
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #define N 100010
 5 using namespace std;
 6 int ans[N][2];
 7 int main(){
 8     int x,y,a,b;
 9     while(cin>>x>>y>>a>>b){
10         int cnt=0;
11         for(int i=a;i<=x;i++){
12             for(int j=b;j<i&&j<=y;j++){
13                 ans[++cnt][0]=i;
14                 ans[cnt][1]=j;
15             }
16         }
17         cout<<cnt<<endl;
18         for(int i=1;i<=cnt;i++)
19             cout<<ans[i][0]<<" "<<ans[i][1]<<endl;
20     }
21     return 0;
22 }

B....

B
 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define N 100010
 5 using namespace std;
 6 struct S{
 7     int l,r,len,id;
 8 }s[N];
 9 bool cmp(S a,S b){
10     return  a.len>b.len;
11 }
12 int main(){
13     int n;
14     while(cin>>n){
15         int ll=(1<<30),rr=-1;
16         for(int i=1;i<=n;i++){
17             cin>>s[i].l>>s[i].r;
18             s[i].len=s[i].r-s[i].l+1;
19             s[i].id=i;
20             ll=min(ll,s[i].l);
21             rr=max(rr,s[i].r);
22         }
23         sort(s+1,s+1+n,cmp);
24         if(s[1].len==(rr-ll+1))
25             cout<<s[1].id<<endl;
26         else
27             cout<<-1<<endl;
28     }
29     return 0;
30 }

C.想了半天也不会。。知道是bfs,但是1e9的范围太尼玛大了。。然后看了下师傅代码。。神奇的map....Orz

C
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<queue>
 4 #include<map>
 5 using namespace std;
 6 typedef long long ll;
 7 const ll N=(ll)1e9;
 8 ll sx,sy,ex,ey;
 9 ll fun(ll x,ll y){
10     return N*(x-1)+y;
11 }
12 map<ll,int>M;
13 int move[8][2]={{0,-1},{0,1},{-1,0},{1,0},{1,1},{1,-1},{-1,-1},{-1,1}};
14 ll solve(){
15     queue<ll>Q[3];
16     Q[0].push(sx);
17     Q[1].push(sy);
18     Q[2].push(0);
19     M[fun(sx,sy)]=-1;
20     while(!Q[1].empty()){
21         ll x=Q[0].front();Q[0].pop();
22         ll y=Q[1].front();Q[1].pop();
23         ll step=Q[2].front();Q[2].pop();
24         if(x==ex&&y==ey)return step;
25         for(int i=0;i<8;i++){
26             ll xx=x+move[i][0];
27             ll yy=y+move[i][1];
28             if(xx<1||xx>N||yy<1||yy>N)continue;
29             if(M[fun(xx,yy)]!=1)continue;
30             Q[0].push(xx);
31             Q[1].push(yy);
32             Q[2].push(step+1);
33             M[fun(xx,yy)]=-1;
34         }
35     }
36     return -1;
37 }
38 int main(){
39     int m;
40     while(cin>>sx>>sy>>ex>>ey){
41         M[fun(sx,sy)]=1;
42         M[fun(ex,ey)]=1;
43         cin>>m;
44         M.clear();
45         int cnt=0;
46         for(int i=1;i<=m;i++){
47             ll r,a,b;
48             cin>>r>>a>>b;
49             for(ll j=a;j<=b;j++){
50                 if(M[fun(r,j)]!=1)
51                     M[fun(r,j)]=1;
52             }
53 
54         }
55         cout<<solve()<<endl;
56     }
57     return 0;
58 }

D.解法:贪心。。。如果当前节点的值是最后不想要的,那么就press一下,因为被press之后就再也不可能回到原来的值了。。。

  尼玛。。比赛的时候看都没看。。。

D
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<vector>
 4 #include<cstring>
 5 #include<algorithm>
 6 #define N 100010
 7 using namespace std;
 8 vector<int>V[N];
 9 int s[N];
10 int x[N],ans[N];
11 bool used[N];
12 int c;
13 void dfs(int rt){
14     for(int i=0;i<V[rt].size();i++)
15         s[V[rt][i]]++;
16     for(int i=0;i<V[rt].size();i++){
17         if(s[V[rt][i]]==x[V[rt][i]]){
18             s[V[rt][i]]++;
19             ans[++c]=V[rt][i];
20             dfs(V[rt][i]);
21         }
22     }
23 }
24 
25 int main(){
26     int n,m;
27     while(cin>>n>>m){
28         memset(s,0,sizeof(s));
29         c=0;
30         memset(used,0,sizeof(used));
31         for(int i=1;i<=n;i++)V[i].clear();
32         for(int i=1;i<=m;i++){
33             int a,b;
34             cin>>a>>b;
35             V[a].push_back(b);
36             V[b].push_back(a);
37         }
38         for(int i=1;i<=n;i++)cin>>x[i];
39         int w;
40         for(int i=1;i<=n;i++){
41             if(s[i]==x[i]){
42                 s[i]++;
43                 dfs(i);
44                 ans[++c]=i;
45             }
46         }
47         cout<<c<<endl;
48         for(int i=1;i<=c;i++)
49             cout<<ans[i]<<" ";
50         cout<<endl;
51     }
52     return 0;
53 }

E.线段树维护即可。。。拆位。。。

  统计每个区间每个二进制位上出现的1的个数。。最后求和的时候加一遍就行。。。异或相当于把这个数位上所以的1变成0.。。0变成1

E
  1 #include<cstdio>
  2 #include<iostream>
  3 #include<cstring>
  4 #include<algorithm>
  5 #define N 100010
  6 #define lson l,m,n<<1
  7 #define rson m+1,r,n<<1|1
  8 using namespace std;
  9 typedef long long ll;
 10 ll s[N<<2][30];
 11 ll flag[N<<2];
 12 ll ans;
 13 void pushup(int n){
 14     for(int i=0;i<30;i++){
 15         s[n][i]=s[n<<1][i]+s[n<<1|1][i];
 16     }
 17 }
 18 void pushdown(int n,int m){
 19     if(flag[n]){
 20         flag[n<<1]^=flag[n];
 21         flag[n<<1|1]^=flag[n];
 22         int f=flag[n];
 23         for(int i=0;i<30;i++){
 24             if(f&1){
 25                 s[n<<1][i]=m-(m>>1)-s[n<<1][i];
 26                 s[n<<1|1][i]=(m>>1)-s[n<<1|1][i];
 27             }
 28             f>>=1;
 29         }
 30         flag[n]=0;
 31     }
 32 }
 33 void build(int l,int r,int n){
 34     memset(s[n],0,sizeof(s[n]));
 35     flag[n]=0;
 36     if(l==r){
 37         int a;
 38         cin>>a;
 39         for(int i=0;i<30;i++){
 40             if(a&1)s[n][i]=1;
 41             a>>=1;
 42         }
 43         return ;
 44     }
 45     int m=(l+r)>>1;
 46     build(lson);
 47     build(rson);
 48     pushup(n);
 49 
 50 }
 51 void update(int ll,int rr,int x,int l,int r,int n){
 52     if(ll==l&&rr==r){
 53         flag[n]^=x;
 54         for(int i=0;i<30;i++){
 55             if(x&1)s[n][i]=(r-l+1)-s[n][i];
 56             x>>=1;
 57         }
 58         return ;
 59     }
 60     pushdown(n,r-l+1);
 61     int m=(l+r)>>1;
 62     if(rr<=m)
 63         update(ll,rr,x,lson);
 64     else if(ll>m)
 65         update(ll,rr,x,rson);
 66     else
 67         update(ll,m,x,lson),update(m+1,rr,x,rson);
 68     pushup(n);
 69 }
 70 void query(int L,int R,int l,int r,int n){
 71     if(L==l&&R==r){
 72         for(int i=0;i<30;i++)
 73             ans+=s[n][i]*(1LL<<i);
 74         return ;
 75     }
 76     pushdown(n,r-l+1);
 77     int m=(l+r)>>1;
 78     if(R<=m)query(L,R,lson);
 79     else if(L>m)query(L,R,rson);
 80     else query(L,m,lson),query(m+1,R,rson);
 81 }
 82 int main(){
 83     int n,m;
 84     int op,l,r,x;
 85     while(cin>>n){
 86         build(1,n,1);
 87         cin>>m;
 88         while(m--){
 89             cin>>op;
 90             if(op==1){
 91                 cin>>l>>r;
 92                 ans=0;
 93                 query(l,r,1,n,1);
 94                 cout<<ans<<endl;
 95             }else{
 96                 cin>>l>>r>>x;
 97                 update(l,r,x,1,n,1);
 98             }
 99         }
100     }
101     return 0;
102 }

 

转载于:https://www.cnblogs.com/silver-bullet/archive/2012/11/12/2766192.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274522.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ui设计卡片阴影_UI设计形状和对象基础知识:阴影和模糊

ui设计卡片阴影第三部分 (Part 3) Welcome to the third part of the UI Design super-basics. This time we’ll cover two of the most commonly used effects — shadows and blurs.欢迎使用UI设计超级基础的第三部分。 这次我们将介绍两种最常用的效果- 阴影和模糊 。 Und…

干货 | 带你玩转前端性能优化!【留言送书】

大家好&#xff0c;我是若川。之前送过三次Vue的书&#xff0c;现在又和博文视点合作再次争取了几本书&#xff0c;具体送书规则看文末。很多人可能有耐心花费一两个小时在一家火锅店门口排队&#xff0c;但几乎没有人愿意等30s去加载一个短视频。事实上&#xff0c;对于大多数…

css3学习手记

完全匹配属性选择器&#xff1a;[idvalue] 包含匹配选择器&#xff1a;[id*value] 首字符匹配选择器&#xff1a;[id^value] 尾字符匹配选择器&#xff1a;[id$value] 阴影&#xff1a;box-shadow:3px 2px 1px #000 /*其他浏览器*/ -webkit-box-shadow:3px 2px 1px #…

如何进入游戏行业_进入设计行业

如何进入游戏行业We’re living in some weird-ass times. One of the unfortunate results of a global pandemic is loss of jobs and financial security. While people continue to deal with this, the prospect of entering a new field — especially one that’s sligh…

据说99%的人不知道 vue-devtools 还能直接打开对应组件文件?

大家好&#xff0c;我是若川。据说 99% 的人不知道 vue-devtools 还能直接打开对应组件文件&#xff1f;本文原理揭秘曾经写过以上这篇文章&#xff0c; 也是源码共读中的第一期(点击文末阅读原文直达)。这个功能如下图所示。欢迎大家来投票&#xff0c;你的投票很重要。如果不…

ux设计中的各种地图_UX设计中的格式塔原理

ux设计中的各种地图Gestalt Theory is the theory of visual perception and how our brain pieces together reality. The theory sheds light on how cognition factors into the way viewers read a piece of design. In the German language “Gestalt” means form or sha…

【ASP】简单Url编码和Url解码实例

描述&#xff1a;在数据传输或读取时&#xff0c;有些敏感数据不宜显示传输&#xff0c;特别涉及机密或财务信息&#xff0c;因此使用编码技术尤为重要。 简单实例&#xff1a; URL编码代码&#xff1a; protected void Button1_Click(object sender, EventArgs e) { …

JetBrains下一代IDE:Fleet 公共预览版发布

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此扫码加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系…

善用工具_如何善用色彩心理学

善用工具There’s a problem with my movement. Most of us in the profession of trying to change the world have little skills or training in the actual craft of influencing human beings to do stuff — especially stuff that is new to them such as composting, p…

看源码的第一步,我猜很多人搞错了~

大家好&#xff0c;我是若川。今天在江西人的前端群里&#xff0c;有个小伙伴问&#xff0c;vueuse 的 vitepress &#xff08;也就是官方文档仓库&#xff09;怎么搭建的&#xff0c;怎么都没有 index.json&#xff08;引用的一个文件&#xff09;。本文简单记录下流程&#x…

序列化说明(转)

序列化是用来通信的&#xff0c;服务端把数据序列化&#xff0c;发送到客户端&#xff0c;客户端把接收到的数据反序列化后对数据进行操作&#xff0c;完成后再序列化发送到服务端&#xff0c;服务端再反序列化数据后对数据进行操作。说白了&#xff0c;数据需要序列化以后才能…

1.1编写目的_1.目的

1.1编写目的A friend of mine recently founded Secta Leagues. A company that organises sports leagues for working professionals, where companies play sports against one another in the same industry. The vision is to provide an app that allows interested comp…

Web 应用架构的下一个转变

Web 技术大概 25 年前开始萌芽&#xff0c;HTTP、HTML、CSS 和 JS 都是在九十年代中期首次被标准化的。直到如今&#xff0c;Web 演变成一个无处不在的应用平台。随着 Web 的发展&#xff0c;Web 应用程序的开发架构也在不断发展。现在有许多用于构建 Web 应用程序的核心架构&a…

生命在于运动?

我有两个朋友&#xff0c;一个喜欢运动&#xff0c;经常打球骑单车&#xff0c;一个就喜欢宅在家里&#xff0c;最多大家玩的时候去旁观。两人常常争执&#xff0c;一个说&#xff1a;生命在于运动&#xff0c;你看我多健康&#xff01;一个说&#xff1a;生命在于静止&#xf…

C++ 学习笔记----类篇

&#xff08;一&#xff09;基本概念&#xff1a; 1、类与对象&#xff1a; 1 //声明类 2 class Human { 3 4 //... Data members and methods go here 5 6 }; 7 8 //定义对象 9 Human human; 2、通常用class声明类&#xff0c;struct也可以&#xff0c;只不过在信…

ux和ui_设计社交餐厅策展应用程序— UX / UI案例研究

ux和uiSabor, which translates from “taste” or “flavor” in Spanish, is a concept for an iOS app designed to provide users with honest, reliable and relatable restaurant recommendations from friends and family. It is a social restaurant curation applicat…

你不知道的 script 标签的 defer 与 async 属性

我持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此扫码加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。另外&#xff1a;目前建…

我是怎么调试 Element UI 源码的

我持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此扫码加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。另外&#xff1a;目前建…

java对象的理解

1、看生成几个对象&#xff0c;就看new了几次&#xff0c; Stu s1new Stu(“张三”); Stu s2s1;-这里也是生成了一个对象&#xff0c;只不过s1和s2指向了同一个对象 2、Stu s1new Stu(“张三”); Stu s2 new Stu(“李四”); s1s2&#xff1b;这里生成了两个对象&#xff0c;但是…

模板缓冲_模板缓冲以及如何使用它可视化体积相交

模板缓冲介绍 (Introduction) The trendy thing in real-time rendering these days is ray-tracing. However, traditional rasterization hasn’t disappeared, and it won’t in the near future. I recommend this blog post on the subject: A hybrid rendering pipeline …