Codeforces Round #337 (Div.2)

本博客讨论了两个算法问题:如何将一根长度为n的木棍切割成四段,使得可以形成矩形但无法形成正方形;以及在有限纸张上绘制最多方块的策略。涉及数论和贪心算法的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                A. Pasha and Stick
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.

Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.

Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.

Output

The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.

Sample test(s)
input
6
output
1
input
20
output
4
Note

There is only one way to divide the stick in the first sample {1, 1, 2, 2}.

Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n;
 7     int i,j,k;
 8     scanf("%d",&n);
 9     if(n%2==0)
10     {
11         int ans=n/4;
12         if(n%4==0)
13             ans--;
14         printf("%d\n",ans);
15     }
16     else
17         printf("0\n");
18 }
View Code
                B. Vika and Squares
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.

Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.

Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has.

The second line of the input contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.

Output

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.

Sample test(s)
input
5
2 4 2 3 3
output
12
input
3
5 5 5
output
15
input
6
10 10 10 1 10 10
output
11
Note

In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.

In the second sample Vika can start to paint using any color.

In the third sample Vika should start painting using color number 5.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int inf=0x3f3f3f3f;
 4 int a[200005];
 5 int main()
 6 {
 7     int n;
 8     int i,j,k;
 9     scanf("%d",&n);
10     int mi=inf,ma=0;
11     for(i=1;i<=n;i++)
12     {
13         scanf("%d",&a[i]);
14         if(a[i]<mi)
15             mi=a[i];
16     }
17     int x=0;
18     for(i=1;i<=n;i++)
19     {
20         if(a[i]==mi)
21             x=0;
22         else
23             x++;
24         if(x>ma)
25             ma=x;
26     }
27     for(i=1;i<=n;i++)
28     {
29         if(a[i]==mi)
30             break;
31         x++;
32         if(x>ma)
33             ma=x;
34     }
35     printf("%I64d\n",1ll*mi*n+1ll*ma);
36 }
View Code
                C. Harmony Analysis
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or  - 1 and any two vectors are orthogonal. Just as a reminder, two vectors in n-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is:

.

Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2k vectors in 2k-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?

Input

The only line of the input contains a single integer k (0 ≤ k ≤ 9).

Output

Print 2k lines consisting of 2k characters each. The j-th character of the i-th line must be equal to ' * ' if the j-th coordinate of the i-th vector is equal to  - 1, and must be equal to ' + ' if it's equal to  + 1. It's guaranteed that the answer always exists.

If there are many correct answers, print any.

Sample test(s)
input
2
output
++**
+*+*
++++
+**+
Note

Consider all scalar products in example:

  • Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0
  • Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0
  • Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0
  • Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0
  • Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0
  • Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 char a[600][600];
 5 int main()
 6 {
 7 
 8     int k,n=1;
 9     int i,j,l;
10     scanf("%d",&k);
11     a[1][1]='+';
12     for(i=1;i<=k;i++)
13     {
14         for(j=1;j<=n;j++)
15         {
16             for(l=1;l<=n;l++)
17             {
18                 a[j][l+n]=a[j][l];
19             }
20             for(l=1;l<=n;l++)
21             {
22                 if(a[j][l]=='+')
23                     a[j+n][l]='*';
24                 else
25                     a[j+n][l]='+';
26                 a[j+n][l+n]=a[j][l];
27             }
28         }
29         n=n*2;
30     }
31     for(i=1;i<=n;i++)
32     {
33         for(j=1;j<=n;j++)
34         {
35             printf("%c",a[i][j]);
36         }
37         printf("\n");
38     }
39     return 0;
40 }
View Code
                D. Vika and Segments
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments parallel to the coordinate axes. All segments have width equal to 1 square, that means every segment occupy some set of neighbouring squares situated in one row or one column.

Your task is to calculate the number of painted cells. If a cell was painted more than once, it should be calculated exactly once.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of segments drawn by Vika.

Each of the next n lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — the coordinates of the endpoints of the segments drawn by Vika. It is guaranteed that all the segments are parallel to coordinate axes. Segments may touch, overlap and even completely coincide.

Output

Print the number of cells painted by Vika. If a cell was painted more than once, it should be calculated exactly once in the answer.

Sample test(s)
input
3
0 1 2 1
1 4 1 2
0 3 2 3
output
8
input
4
-2 -1 2 -1
2 1 -2 1
-1 -2 -1 2
1 2 1 -2
output
16
Note

In the first sample Vika will paint squares (0, 1), (1, 1), (2, 1), (1, 2), (1, 3), (1, 4), (0, 3) and (2, 3).

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 const int inf=0x3f3f3f3f;
  4 struct Node
  5 {
  6     int u;
  7     int v;
  8     int h;
  9     int c;
 10 };
 11 
 12 Node a[200005],e[100005],f[100005];
 13 int tree[200005],n,l,m1,m2,num,b[200005];
 14 long long sum;
 15 map <int,int> d;
 16 
 17 void add(int k,int val)
 18 {
 19     while(k<=num)
 20     {
 21         tree[k]+=val;
 22         k+=k&-k;
 23     }
 24 }
 25 
 26 int read(int k)
 27 {
 28     int Sum=0;
 29     while(k)
 30     {
 31         Sum+=tree[k];
 32         k-=k&-k;
 33     }
 34     return Sum;
 35 }
 36 
 37 bool cmp(Node o,Node p)
 38 {
 39     if(o.h!=p.h)
 40     {
 41         return o.h<p.h;
 42     }
 43     else
 44         return o.u<p.u;
 45 }
 46 
 47 bool cmp2(Node o,Node p)
 48 {
 49     if(o.h!=p.h)
 50     {
 51         return o.h<p.h;
 52     }
 53     else
 54     {
 55         return o.c>p.c;
 56     }
 57 }
 58 
 59 void Unite()
 60 {
 61     int i,j,now,newu,newv;
 62     sort(e+1,e+m1+1,cmp);
 63     sort(f+1,f+m2+1,cmp);
 64 
 65     now=inf;
 66     for(i=1;i<=m1;i++)
 67     {
 68         if(e[i].h!=now)
 69         {
 70             //printf("h\n");
 71             if(now!=inf)
 72             {
 73                 l++;
 74                 a[l].u=now,a[l].h=newu,a[l].c=1;
 75                 l++;
 76                 a[l].u=now,a[l].h=newv,a[l].c=-1;
 77                 sum=sum+newv-newu+1;
 78                 if(d[now]!=1)
 79                 {
 80                     b[++num]=now;d[now]=1;
 81                 }
 82             }
 83             now=e[i].h;
 84             newu=e[i].u,newv=e[i].v;
 85         }
 86         else
 87         {
 88             if(e[i].u<=newv)
 89             {
 90                 newv=max(newv,e[i].v);
 91             }
 92             else
 93             {
 94                 l++;
 95                 a[l].u=now,a[l].h=newu,a[l].c=1;
 96                 l++;
 97                 a[l].u=now,a[l].h=newv,a[l].c=-1;
 98                 sum=sum+newv-newu+1;
 99                 if(d[now]!=1)
100                 {
101                     b[++num]=now;d[now]=1;
102                 }
103                 newu=e[i].u,newv=e[i].v;
104             }
105         }
106     }
107     if(now!=inf)
108     {
109         l++;
110         a[l].u=now,a[l].h=newu,a[l].c=1;
111         l++;
112         a[l].u=now,a[l].h=newv,a[l].c=-1;
113         sum=sum+newv-newu+1;
114         if(d[now]!=1)
115         {
116             b[++num]=now;d[now]=1;
117         }
118     }
119     //printf("^%I64d\n",sum);
120     now=inf;
121     for(i=1;i<=m2;i++)
122     {
123         if(f[i].h!=now)
124         {
125             if(now!=inf)
126             {
127                 l++;
128                 a[l].u=newu,a[l].v=newv,a[l].h=now,a[l].c=0;
129                 sum=sum+newv-newu+1;
130                 if(d[newu]!=1)
131                 {
132                     b[++num]=newu;d[newu]=1;
133                 }
134                 if(d[newv]!=1)
135                 {
136                     b[++num]=newv;d[newv]=1;
137                 }
138             }
139             now=f[i].h;
140             newu=f[i].u,newv=f[i].v;
141         }
142         else
143         {
144             if(f[i].u<=newv)
145             {
146                 newv=max(newv,f[i].v);
147             }
148             else
149             {
150                 l++;
151                 a[l].u=newu,a[l].v=newv,a[l].h=now,a[l].c=0;
152                 sum=sum+newv-newu+1;
153                 if(d[newu]!=1)
154                 {
155                     b[++num]=newu;d[newu]=1;
156                 }
157                 if(d[newv]!=1)
158                 {
159                     b[++num]=newv;d[newv]=1;
160                 }
161                 newu=f[i].u,newv=f[i].v;
162             }
163         }
164     }
165     if(now!=inf)
166     {
167         l++;
168         a[l].u=newu,a[l].v=newv,a[l].h=now,a[l].c=0;
169         sum=sum+newv-newu+1;
170         if(d[newu]!=1)
171         {
172             b[++num]=newu;d[newu]=1;
173         }
174         if(d[newv]!=1)
175         {
176             b[++num]=newv;d[newv]=1;
177         }
178     }
179 }
180 
181 int main()
182 {
183     int i,j;
184     int x1,x2,y1,y2;
185     memset(tree,0,sizeof(tree));d.clear();
186     m1=0,m2=0,l=0,num=0;  sum=0;
187 
188     scanf("%d",&n);
189     for(i=1;i<=n;i++)
190     {
191         scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
192 
193         if(x1==x2 && y1!=y2)            //垂直
194         {
195             if(y1>y2)
196                 swap(y1,y2);
197             m1++;
198             e[m1].u=y1,e[m1].v=y2,e[m1].h=x1,e[m1].c=1;
199         }
200         else                            //水平
201         {
202             if(x1>x2)
203                 swap(x1,x2);
204             m2++;
205             f[m2].u=x1,f[m2].v=x2,f[m2].h=y1,f[m2].c=2;
206         }
207     }
208 
209     Unite();
210     sort(b+1,b+num+1);
211     sort(a+1,a+l+1,cmp2);
212     //printf("%d %d %d %d\n",m1,m2,num,l);
213     //printf("%I64d\n",sum);
214     for(i=1;i<=l;i++)
215     {
216         if(a[i].c==0)
217         {
218             int s;
219             x1=lower_bound(b+1,b+num+1,a[i].u)-b;
220             x2=lower_bound(b+1,b+num+1,a[i].v)-b;
221             s=read(x2)-read(x1-1);
222             //printf("^^%d:%d %d:%d %d\n",x1,read(x1-1),x2,read(x2),s);
223             sum=sum-s;
224         }
225         else
226         {
227             x1=lower_bound(b+1,b+num+1,a[i].u)-b;
228             //printf("^^^%d %d\n",x1,a[i].c);
229             add(x1,a[i].c);
230         }
231     }
232 
233     printf("%I64d\n",sum);
234 
235 }
View Code

 

 

转载于:https://www.cnblogs.com/cyd308/p/5140498.html

【基于QT的调色板】是一个使用Qt框架开发的色彩选择工具,类似于Windows操作系统中常见的颜色选取器。Qt是一个跨平台的应用程序开发框架,广泛应用于桌面、移动和嵌入式设备,支持C++和QML语言。这个调色板功能提供了横竖两种渐变模式,用户可以方便地选取所需的颜色值。 在Qt中,调色板(QPalette)是一个关键的类,用于管理应用程序的视觉样式。QPalette包含了一系列的颜色角色,如背景色、前景色、文本色、高亮色等,这些颜色可以根据用户的系统设置或应用程序的需求进行定制。通过自定义QPalette,开发者可以创建具有独特视觉风格的应用程序。 该调色板功能可能使用了QColorDialog,这是一个标准的Qt对话框,允许用户选择颜色。QColorDialog提供了一种简单的方式来获取用户的颜色选择,通常包括一个调色板界面,用户可以通过滑动或点击来选择RGB、HSV或其他色彩模型中的颜色。 横渐变取色可能通过QGradient实现,QGradient允许开发者创建线性或径向的色彩渐变。线性渐变(QLinearGradient)沿直线从一个点到另一个点过渡颜色,而径向渐变(QRadialGradient)则以圆心为中心向外扩散颜色。在调色板中,用户可能可以通过滑动条或鼠标拖动来改变渐变的位置,从而选取不同位置的颜色。 竖渐变取色则可能是通过调整QGradient的方向来实现的,将原本水平的渐变方向改为垂直。这种设计可以提供另一种方式来探索颜色空间,使得选取颜色更为直观和便捷。 在【colorpanelhsb】这个文件名中,我们可以推测这是与HSB(色相、饱和度、亮度)色彩模型相关的代码或资源。HSB模型是另一种常见且直观的颜色表示方式,与RGB或CMYK模型不同,它以人的感知为基础,更容易理解。在这个调色板中,用户可能可以通过调整H、S、B三个参数来选取所需的颜色。 基于QT的调色板是一个利用Qt框架和其提供的色彩管理工具,如QPalette、QColorDialog、QGradient等,构建的交互式颜色选择组件。它不仅提供了横竖渐变的色彩选取方式,还可能支持HSB色彩模型,使得用户在开发图形用户界面时能更加灵活和精准地控制色彩。
标题基于Spring Boot的二手物品交易网站系统研究AI更换标题第1章引言阐述基于Spring Boot开发二手物品交易网站的研究背景、意义、现状及本文方法与创新点。1.1研究背景与意义介绍二手物品交易的市场需求和Spring Boot技术的适用性。1.2国内外研究现状概述当前二手物品交易网站的发展现状和趋势。1.3论文方法与创新点说明本文采用的研究方法和在系统设计中的创新之处。第2章相关理论与技术介绍开发二手物品交易网站所涉及的相关理论和关键技术。2.1Spring Boot框架解释Spring Boot的核心概念和主要特性。2.2数据库技术讨论适用的数据库技术及其在系统中的角色。2.3前端技术阐述与后端配合的前端技术及其在系统中的应用。第3章系统需求分析详细分析二手物品交易网站系统的功能需求和性能需求。3.1功能需求列举系统应实现的主要功能模块。3.2性能需求明确系统应满足的性能指标和安全性要求。第4章系统设计与实现具体描述基于Spring Boot的二手物品交易网站系统的设计和实现过程。4.1系统架构设计给出系统的整体架构设计和各模块间的交互方式。4.2数据库设计详细阐述数据库的结构设计和数据操作流程。4.3界面设计与实现介绍系统的界面设计和用户交互的实现细节。第5章系统测试与优化说明对系统进行测试的方法和性能优化的措施。5.1测试方法与步骤测试环境的搭建、测试数据的准备及测试流程。5.2测试结果分析对测试结果进行详细分析,验证系统是否满足需求。5.3性能优化措施提出针对系统性能瓶颈的优化建议和实施方案。第6章结论与展望总结研究成果,并展望未来可能的研究方向和改进空间。6.1研究结论概括本文基于Spring Boot开发二手物品交易网站的主要发现和成果。6.2展望与改进讨论未来可能的系统改进方向和新的功能拓展。
1. 用户与权限管理模块 角色管理: 学生:查看个人住宿信息、提交报修申请、查看卫生检查结果、请假外出登记 宿管人员:分配宿舍床位、处理报修申请、记录卫生检查结果、登记晚归情况 管理员:维护楼栋与房间信息、管理用户账号、统计住宿数据、发布宿舍通知 用户操作: 登录认证:对接学校统一身份认证(模拟实现,用学号 / 工号作为账号),支持密码重置 信息管理:学生完善个人信息(院系、专业、联系电话),管理员维护所有用户信息 权限控制:不同角色仅可见对应功能(如学生无法修改床位分配信息) 2. 宿舍信息管理模块 楼栋与房间管理: 楼栋信息:名称(如 "1 号宿舍楼")、层数、性别限制(男 / 女 / 混合)、管理员(宿管) 房间信息:房间号(如 "101")、户型(4 人间 / 6 人间)、床位数量、已住人数、可用状态 设施信息:记录房间内设施(如空调、热水器、桌椅)的配置与完好状态 床位管理: 床位编号:为每个床位设置唯一编号(如 "101-1" 表示 101 房间 1 号床) 状态标记:标记床位为 "空闲 / 已分配 / 维修中",支持批量查询空闲床位 历史记录:保存床位的分配变更记录(如从学生 A 调换到学生 B 的时间与原因) 3. 住宿分配与调整模块 住宿分配: 新生分配:管理员导入新生名单后,宿管可按专业集中、性别匹配等规则批量分配床位 手动分配:针对转专业、复学学生,宿管手动指定空闲床位并记录分配时间 分配结果公示:学生登录后可查看自己的宿舍信息(楼栋、房间号、床位号、室友列表) 调整管理: 调宿申请:学生提交调宿原因(如室友矛盾、身体原因),选择意向宿舍(需有空位) 审批流程:宿管审核申请,通过后执行床位调换,更新双方住宿信息 换宿记录:保存调宿历史(申请人、原床位、新床位、审批人、时间) 4. 报修与安全管理模块 报修管理: 报修提交:学生选择宿舍、设施类型(如 "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值