Codeforces Round #194 (Div. 2) 部分题解

本文深入探讨了编程领域的核心概念,包括数据结构、算法、版本控制等,通过具体实例展示了如何应用这些技术解决实际问题。

A: 题意:把n*n 个数 分成 n组,每组的总和都一样

解法:比如n等于4,然后可以得到个矩阵    1    2    3    4

                                                        5    6    7    8

                                                        9    10   11   12

                                                       13    14   15   16

     你要分成n组和相同的, 每组里面必须从原来里每行取个最大的,第二大的,第三大的,第四大的

   

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int n,k;
11     scanf("%d",&n);
12     for(int i = 0; i < n; i++) //输出 n 行 
13     {
14         k = 0;
15         for(int j = i; j < n+i; j++) //每行输出n个数 
16         {
17             printf("%d ",j%n+1+n*k);
18             k++;
19         }
20         printf("\n");
21     }
22     return 0;
23  } 
View Code

B:题意:给你八个点,构成1个矩形,x1<x2<x3,y1<y2<y3这三种类型,(x2,y2)不在矩形里 ,注意判重。。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 struct node
 9 {
10     int x;
11     int y;
12 }a[10];
13 
14 int b1[10],b2[10];
15 
16 bool cmp1(node m,node n)
17 {
18     return m.x < n.x;
19 }
20 
21 bool cmp2(node m,node n)
22 {
23     return m.y < n.y;
24 }
25 
26 int main()
27 {
28     memset(b1,0,sizeof(b1));
29     memset(b2,0,sizeof(b2));
30     for(int i=0; i<8; i++)
31     cin>>a[i].x>>a[i].y;
32     sort(a,a+8,cmp1);
33     for(int i=0; i<8; i++)
34     for(int j=i+1; j<8; j++)
35     {
36         if(a[i].x==a[j].x && a[i].y==a[j].y)
37         {
38             printf("ugly\n");
39             return 0;
40         }
41     }
42     int cnt=0,co=1;
43     for(int i=1; i<8; i++)
44     {
45         if(a[i].x != a[i-1].x)
46         {
47             cnt++;
48             b1[cnt] = co;
49             co = 1;
50         }
51         else co++;
52     }
53     if(a[6].x == a[7].x) 
54     {
55         b1[++cnt] = co;
56     } 
57     sort(a,a+8,cmp2);
58     co = 1;
59     cnt = 0;
60     for(int i=1; i<8; i++)
61     {
62         if(a[i].y != a[i-1].y)
63         {
64             cnt++;
65             b2[cnt] = co;
66             co = 0;
67         }
68         co++;
69     }
70     if(a[6].y == a[7].y) 
71     {
72         b2[++cnt] = co;
73     } 
74     int flag1=0,flag2=0;
75     if(b1[1]==3&&b1[2]==2&&b1[3]==3) flag1 = 1;
76     if(b2[1]==3&&b2[2]==2&&b2[3]==3) flag2 = 1;
77     if(flag1&&flag2) printf("respectable\n");
78     else printf("ugly\n");
79     return 0;
80 }
View Code

C题意: 用面值为3的次幂的硬币 购买价值为n的商品 , 要求硬币总价值>n且硬币数最多

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <algorithm>
 6 using namespace std;
 7 __int64 n;
 8 int main()
 9 {
10     while(scanf("%I64d",&n)!=EOF)
11     {
12         while(n%3==0)n/=3;
13         printf("%I64d\n",((n+2)/3));
14     }
15     return 0;
16 }
View Code

 

转载于:https://www.cnblogs.com/ar940507/p/3221910.html

### 关于Codeforces Round 704 Div. 2 的信息 对于Codeforces Round 704 Div. 2的比赛,虽然未直接提及具体题目解析或参赛体验的内容,但是可以根据平台的一贯风格推测该轮比赛同样包含了多种算法挑战。通常这类赛事会涉及数据结构、动态规划、图论等方面的知识。 考虑到提供的参考资料并未覆盖到此特定编号的比赛详情[^1],建议访问Codeforces官方网站查询官方题解或是浏览社区论坛获取其他选手分享的经验总结。一般而言,在赛后不久就会有详细的解答发布出来供学习交流之用。 为了帮助理解同类型的竞赛内容,这里提供了一个基于过往相似赛事的例子——如何通过居中子数组特性来解决问题的方法: ```cpp // 假设有一个函数用于处理给定条件下的数组恢复问题 vector<int> restoreArray(vector<vector<int>>& adjacentPairs) { unordered_map<int, vector<int>> adj; for (auto& p : adjacentPairs){ adj[p[0]].push_back(p[1]); adj[p[1]].push_back(p[0]); } int start = 0; for(auto& [num, neighbors] : adj){ if(neighbors.size() == 1){ start = num; break; } } vector<int> res(adjacentPairs.size() + 1); unordered_set<int> seen; function<void(int,int)> dfs = [&](int node, int idx){ seen.insert(node); res[idx] = node; for(auto next : adj[node]){ if(!seen.count(next)){ dfs(next, idx + 1); } } }; dfs(start, 0); return res; } ``` 上述代码展示了利用深度优先搜索(DFS)重建原始序列的一种方式,这某些情况下解决Codeforces比赛中遇到的问题思路相吻合[^4]。 #### 注意事项 由于缺乏针对Codeforces Round 704 Div. 2的具体材料支持,以上解释更多依赖于对同类活动的理解以及编程技巧的应用实例来进行说明。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值