CF Bayan Contest Warm Up round (Oct 5th)

本文解析了四道CF(CodeForces)竞赛题目,包括简单的二维数组绘图、路径可达性判断、复杂度较高的DFS应用以及涉及区间枚举和最大公约数(GCD)计算的思维题。提供了详细的解题思路与代码实现。

2014-10-06 15:13:20

这场CF有点丧病QAQ。

A:打表画图题,先用二维数组存图,然后输出。(写的搓搓的~)

 1 /*************************************************************************
 2     > File Name: a.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Sun 05 Oct 2014 09:02:46 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <queue>
16 #include <iostream>
17 #include <algorithm>
18 using namespace std;
19 #define lp (p << 1)
20 #define rp (p << 1|1)
21 #define getmid(l,r) (l + (r - l) / 2)
22 #define MP(a,b) make_pair(a,b)
23 typedef long long ll;
24 const int INF = 1 << 30;
25 
26 int k;
27 int g[50][50];
28 
29 int main(){
30     memset(g,0,sizeof(g));
31     scanf("%d",&k);
32     int i,j;
33     if(k <= 4){
34         for(i = 1; i <= k; ++i)
35             g[i][1] = 1;
36     }
37     else{
38         for(i = 1; i <= 4; ++i) g[i][1] = 1;
39         k -= 4;
40         i = 1,j = 2;
41         while(k){
42             g[i][j] = 1;
43             ++i;
44             if(i == 3) i = 4;
45             if(i > 4){
46                 i = 1;
47                 ++j;
48             }
49             --k;
50         }
51     }
52     printf("+------------------------+\n");
53     for(i = 1; i <= 2; ++i){
54         printf("|");
55         for(j = 1; j <= 11; ++j)
56             printf("%c.",g[i][j] ? 'O' : '#');
57         if(i == 1) printf("|D|)\n");
58         else printf("|.|\n");
59     }
60     printf("|%c.......................|\n",g[3][1] ? 'O' : '#');
61     printf("|");
62     for(j = 1; j <= 11; ++j)
63         printf("%c.",g[4][j] ? 'O' : '#');
64     printf("|.|)\n");
65     printf("+------------------------+\n");
66     return 0;
67 }

 

B:这题被我YY出来了(QAQ),只要判断四个角是否堵死就可以了,为什么呢?

  因为如果四个角不堵死,那么最外圈形成环路,从任意一点出发先到最外圈环路,然后可以到任意一点。

 1 /*************************************************************************
 2     > File Name: b.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Sun 05 Oct 2014 09:20:56 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <queue>
16 #include <iostream>
17 #include <algorithm>
18 using namespace std;
19 #define lp (p << 1)
20 #define rp (p << 1|1)
21 #define getmid(l,r) (l + (r - l) / 2)
22 #define MP(a,b) make_pair(a,b)
23 typedef long long ll;
24 const int INF = 1 << 30;
25 
26 int main(){
27     int n,m;
28     char s1[50],s2[50];
29     scanf("%d%d",&n,&m);
30     scanf("%s%s",s1 + 1,s2 + 1);
31     int flag = 1;
32     if(s1[1] == '<' && s2[1] == '^') flag = 0;
33     if(s1[1] == '>' && s2[m] == '^') flag = 0;
34     if(s1[n] == '<' && s2[1] == 'v') flag = 0;
35     if(s1[n] == '>' && s2[m] == 'v') flag = 0;
36     if(flag) printf("YES\n");
37     else printf("NO\n");
38     return 0;
39 }

C:比赛的时候想了一个看起来很神但写起来巨麻烦的算法.... 赛后看别人DFS好像很优雅QAQ。写不动了orz。

D:练思维的好题,其实没什么算法。思路:大题想法是枚举区间右端点。设当前读进来第 i 个数,且此时已经处理出前 i - 1个数所有可能的gcd值(而且求出该gcd值出现次数),那么将第 i 个数和所有可能gcd值再求一次gcd,需要保存的仅是该轮求出的所有gcd(相当于滚动数组思想),需要用map来记录gcd出现次数。 细节见代码。

第一次写了一个姿势比较丑的代码 400+ms QAQ

 1 /*************************************************************************
 2     > File Name: d.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Mon 06 Oct 2014 12:50:08 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <queue>
16 #include <iostream>
17 #include <algorithm>
18 using namespace std;
19 #define lp (p << 1)
20 #define rp (p << 1|1)
21 #define getmid(l,r) (l + (r - l) / 2)
22 #define MP(a,b) make_pair(a,b)
23 typedef long long ll;
24 const int INF = 1 << 30;
25 const int maxn = 100010;
26 
27 int Gcd(int a,int b){ return b == 0 ? a : Gcd(b,a % b);}
28 
29 int n,q;
30 int a[maxn],val[maxn],cnt[maxn],sz;
31 map<ll,ll> mp,mp1,mp2;
32 
33 void Add(int v,int c){
34     if(mp2.find(v) == mp2.end()) mp2[v] = 1;
35     mp1[v] += c;
36 }
37 
38 int main(){
39     scanf("%d",&n);
40     for(int i = 1; i <= n; ++i)
41         scanf("%d",a + i);
42     for(int i = 1; i <= n; ++i){
43         mp1.clear();
44         int tsz = sz;
45         sz = 0;
46         for(int j = 1; j <= tsz; ++j){
47             int c = mp2[val[j]];
48             val[++sz] = Gcd(val[j],a[i]);
49             Add(val[sz],c);
50         }
51         val[++sz] = a[i];
52         Add(val[sz],1);
53         sort(val + 1,val + sz + 1);
54         sz = unique(val + 1,val + sz + 1) - val - 1;
55         for(int j = 1; j <= sz; ++j){
56             if(mp.find(val[j]) == mp.end()) mp[val[j]] = 0;
57             mp[val[j]] += mp1[val[j]];
58         }
59         //for(int j = 1; j <= sz; ++j){
60            // printf("val :%d , num %d sum %d\n",val[j],mp1[val[j]],mp[val[j]]);
61         //}
62         mp2 = mp1;
63     }
64     scanf("%d",&q);
65     int x;
66     while(q--){
67         scanf("%d",&x);
68         if(mp.find(x) == mp.end()) printf("0\n");
69         else    printf("%I64d\n",mp[x]);
70     }
71     return 0;
72 }
View Code

参考通神的代码,优化了下,100+ms

 1 /*************************************************************************
 2     > File Name: d.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Mon 06 Oct 2014 12:50:08 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <queue>
16 #include <iostream>
17 #include <algorithm>
18 using namespace std;
19 #define lp (p << 1)
20 #define rp (p << 1|1)
21 #define getmid(l,r) (l + (r - l) / 2)
22 #define MP(a,b) make_pair(a,b)
23 typedef long long ll;
24 const int INF = 1 << 30;
25 const int maxn = 100010;
26 
27 int Gcd(int a,int b){ return b == 0 ? a : Gcd(b,a % b);}
28 
29 int n,q;
30 int a[maxn],sz,tsz;
31 map<int,ll> mp;
32 pair<int,int> val[maxn];
33 
34 int main(){
35     scanf("%d",&n);
36     for(int i = 1; i <= n; ++i)
37         scanf("%d",a + i);
38     sz = 0;
39     for(int i = 1; i <= n; ++i){
40         for(int j = 1; j <= sz; ++j)
41             val[j].first = Gcd(val[j].first,a[i]);
42         val[++sz] = MP(a[i],1);
43         tsz = 1;
44         for(int j = 2; j <= sz; ++j){
45             if(val[tsz].first == val[j].first) val[tsz].second += val[j].second;
46             else val[++tsz] = val[j];
47         }
48         sz = tsz;
49         for(int j = 1; j <= sz; ++j){
50             if(mp.find(val[j].first) == mp.end()) mp[val[j].first] = 0;
51             mp[val[j].first] += val[j].second;
52         }
53     }
54     scanf("%d",&q);
55     int x;
56     while(q--){
57         scanf("%d",&x);
58         if(mp.find(x) == mp.end()) printf("0\n");
59         else    printf("%I64d\n",mp[x]);
60     }
61     return 0;
62 }

 

转载于:https://www.cnblogs.com/naturepengchen/articles/4008318.html

标题中提及的“BOE-B2-154-240-JD9851-Gamma2.2_190903.rar”标识了一款由京东方公司生产的液晶显示单元,属于B2产品线,物理规格为154毫米乘以240毫米,适配于JD9851型号设备,并采用Gamma2.2标准进行色彩校正,文档生成日期为2019年9月3日。该压缩文件内包含的代码资源主要涉及液晶模块的底层控制程序,采用C/C++语言编写,用于管理显示屏的基础运行功能。 液晶模块驱动作为嵌入式系统的核心软件组成部分,承担着直接操控显示硬件的任务,其关键作用在于通过寄存器读写机制来调整屏幕的各项视觉参数,包括亮度、对比度及色彩表现,同时负责屏幕的启动与关闭流程。在C/C++环境下开发此类驱动需掌握若干关键技术要素: 首先,硬件寄存器的访问依赖于输入输出操作,常借助内存映射技术实现,例如在Linux平台使用`mmap()`函数将寄存器地址映射至用户内存空间,进而通过指针进行直接操控。 其次,驱动需处理可能产生的中断信号,如帧缓冲区更新完成事件,因此需注册相应的中断服务例程以实时响应硬件事件。 第三,为确保多线程或进程环境下共享资源(如寄存器)的安全访问,必须引入互斥锁、信号量等同步机制来避免数据竞争。 第四,在基于设备树的嵌入式Linux系统中,驱动需依据设备树节点中定义的硬件配置信息完成初始化与参数设置。 第五,帧缓冲区的管理至关重要,驱动需维护该内存区域,保证图像数据准确写入并及时刷新至显示面板。 第六,为优化能耗,驱动应集成电源管理功能,通过寄存器控制实现屏幕的休眠与唤醒状态切换。 第七,针对不同显示设备支持的色彩格式差异,驱动可能需执行色彩空间转换运算以适配目标设备的色彩输出要求。 第八,驱动开发需熟悉液晶显示控制器与主处理器间的通信接口协议,如SPI、I2C或LVDS等串行或并行传输标准。 最后,完成代码编写后需进行系统化验证,包括基础显示功能测试、性能评估及异常处理能力检验,确保驱动稳定可靠。 该源代码集合为深入理解液晶显示控制原理及底层驱动开发实践提供了重要参考,通过剖析代码结构可掌握硬件驱动设计的具体方法与技术细节。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值