CODEFORCES近期总结

Codeforces Round #636 (Div. 3)
A. Candies
Recently Vova found nn candy wrappers. He remembers that he bought xx candies during the first day, 2x2x candies during the second day, 4x4x candies during the third day, ……, 2k−1x2k−1x candies during the kk-th day. But there is an issue: Vova remembers neither xx nor kk but he is sure that xx and kk are positive integers and k>1k>1.Vova will be satisfied if you tell him any positive integer xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n. It is guaranteed that at least one solution exists. Note that k>1k>1.You have to answer tt independent test cases.InputThe first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.The only line of the test case contains one integer nn (3≤n≤1093≤n≤109) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer xx and integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n.OutputPrint one integer — any positive integer value of xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n.ExampleinputCopy7
3
6
7
21
28
999999999
999999984
outputCopy1
2
1
7
4
333333333
333333328
Note
In the first test case of the example, one of the possible answers is x=1,k=2x=1,k=2. Then 1⋅1+2⋅11⋅1+2⋅1 equals n=3n=3.In the second test case of the example, one of the possible answers is x=2,k=2x=2,k=2. Then 1⋅2+2⋅21⋅2+2⋅2 equals n=6n=6.In the third test case of the example, one of the possible answers is x=1,k=3x=1,k=3. Then 1⋅1+2⋅1+4⋅11⋅1+2⋅1+4⋅1 equals n=7n=7.In the fourth test case of the example, one of the possible answers is x=7,k=2x=7,k=2. Then 1⋅7+2⋅71⋅7+2⋅7 equals n=21n=21.In the fifth test case of the example, one of the possible answers is x=4,k=3x=4,k=3. Then 1⋅4+2⋅4+4⋅41⋅4+2⋅4+4⋅4 equals n=28n=28.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long long  n;
        cin >> n;
        long long m = 3, k = 4;
        while (n % m != 0)
        {
            m += k;
            k = k * 2;
        }
        cout << n / m << endl;
    }
    return 0;
}

题目大意是对于一个数N,找到他的一个因数X,使得X*(2的等比数列和)=N,同时保证X尽可能大(有多组X,K符合条件时,取X大的一组),这题我一开始卡了好久,因为我同时循环了X,K导致超时,而这题的本质是一重循环,即把X看作N/(2的等比数列和,记为M),M从小到大进行循环,同时判断是否整除

Codeforces Round #637 (Div. 2) - Thanks, Ivan Belonogov!
A. Nastya and Rice
Nastya just made a huge mistake and dropped a whole package of rice on the floor. Mom will come soon. If she sees this, then Nastya will be punished.In total, Nastya dropped nn grains. Nastya read that each grain weighs some integer number of grams from a−ba−b to a+ba+b, inclusive (numbers aa and bb are known), and the whole package of nn grains weighs from c−dc−d to c+dc+d grams, inclusive (numbers cc and dd are known). The weight of the package is the sum of the weights of all nn grains in it.Help Nastya understand if this information can be correct. In other words, check whether each grain can have such a mass that the ii-th grain weighs some integer number xixi (a−b≤xi≤a+b)(a−b≤xi≤a+b), and in total they weigh from c−dc−d to c+dc+d, inclusive (c−d≤∑i=1nxi≤c+dc−d≤∑i=1nxi≤c+d).InputThe input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1000)(1≤t≤1000) — the number of test cases.The next tt lines contain descriptions of the test cases, each line contains 55 integers: nn (1≤n≤1000)(1≤n≤1000) — the number of grains that Nastya counted and a,b,c,da,b,c,d (0≤b<a≤1000,0≤d<c≤1000)(0≤b<a≤1000,0≤d<c≤1000) — numbers that determine the possible weight of one grain of rice (from a−ba−b to a+ba+b) and the possible total weight of the package (from c−dc−d to c+dc+d).OutputFor each test case given in the input print “Yes”, if the information about the weights is not inconsistent, and print “No” if nn grains with masses from a−ba−b to a+ba+b cannot make a package with a total mass from c−dc−d to c+dc+d.ExampleinputCopy5
7 20 3 101 18
11 11 10 234 2
8 9 7 250 122
19 41 21 321 10
3 10 8 6 1
outputCopyYes
No
Yes
No
Yes
Note
In the first test case of the example, we can assume that each grain weighs 1717 grams, and a pack 119119 grams, then really Nastya could collect the whole pack.In the third test case of the example, we can assume that each grain weighs 1616 grams, and a pack 128128 grams, then really Nastya could collect the whole pack.In the fifth test case of the example, we can be assumed that 33 grains of rice weigh 22, 22, and 33 grams, and a pack is 77 grams, then really Nastya could collect the whole pack.In the second and fourth test cases of the example, we can prove that it is impossible to determine the correct weight of all grains of rice and the weight of the pack so that the weight of the pack is equal to the total weight of all collected grains.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
 int t;
 cin >> t;
 while (t--) {
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  int l=n*(a-b),r=n*(a+b);
  if (r<c-d||c+d<l)
   cout << "No"<<endl;
  else
   cout << "Yes"<<endl;
 }
    return 0;
}

大意就是一个统计的问题,问总数在不在范围内,思路大致相同,但还不知道为什么没过
bool f = 0;
for (int i = a - b; i <= a + b; i++)
if ((n * i) >= (c - d) && (n * i) <= (c + d))
{
f = 1;
break;
}
if (f == 1) cout << “Yes” << endl;
else cout << “No” << endl;
这是报错 Checker Logwrong answer expected YES, found NO [124th token]意为124个错了
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200429145846516.png在这里插入图片描述

看他测试数据可以发现其实是有规律的,我特地根据规律找到了第124个:14140,但发现结果是一样的,所以我暂时还没发现错哪(不是超时)

B. Nastya and Door
https://blog.csdn.net/li_wen_zhuo/article/details/105725569
自己的简化功夫还是没到家,只想到了将山峰单独出来,但没想到可以直接相减得到区间山峰数

Educational Codeforces Round 86 (Rated for Div. 2)
B. Binary Period
Let’s say string ss has period kk if si=si+ksi=si+k for all ii from 11 to |s|−k|s|−k (|s||s| means length of string ss) and kk is the minimum positive integer with this property.Some examples of a period: for ss=“0101” the period is k=2k=2, for ss=“0000” the period is k=1k=1, for ss=“010” the period is k=2k=2, for ss=“0011” the period is k=4k=4.You are given string tt consisting only of 0’s and 1’s and you need to find such string ss that:String ss consists only of 0’s and 1’s;The length of ss doesn’t exceed 2⋅|t|2⋅|t|;String tt is a subsequence of string ss;String ss has smallest possible period among all strings that meet conditions 1—3.Let us recall that tt is a subsequence of ss if tt can be derived from ss by deleting zero or more elements (any) without changing the order of the remaining elements. For example, tt=“011” is a subsequence of ss=“10101”.InputThe first line contains single integer TT (1≤T≤1001≤T≤100) — the number of test cases.Next TT lines contain test cases — one per line. Each line contains string tt (1≤|t|≤1001≤|t|≤100) consisting only of 0’s and 1’s.OutputPrint one string for each test case — string ss you needed to find. If there are multiple solutions print any one of them.ExampleinputCopy4
00
01
111
110
outputCopy00
01
11111
1010
Note
In the first and second test cases, s=ts=t since it’s already one of the optimal solutions. Answers have periods equal to 11 and 22, respectively.In the third test case, there are shorter optimal solutions, but it’s okay since we don’t need to minimize the string ss. String ss has period equal to 11.
题目大意是找到最小的K,使得添加后,不超过原序列长度的两倍的新序列为K循环序列(每K个相同)

#include<bits/stdc++.h>
using namespace std;
int main(){
 int T;
 cin>>T;
 while(T--){
  string s;
  cin>>s;
  bool same = 1;
  for(char c:s) if(c!=s[0]) same=0;
  if(same)
   cout<<s<<endl;
  else{
   for(int i=0;i<2*s.size();i++)
    cout<<(i%2);
   cout<<endl;
  }
 }
 return 0;
}

代码是提交时翻到别人记录看到的,不是我写的,codeblock运行不了,char c:s意为
for(int i=0;i<s.length();i++)
char c=s[i];
更新一下:看了别人的题解大概看懂了,题目中有很多提示的数据,有序列k=3,4,但实际上,仔细想一想,任一个序列,都可以是他两倍长度010101……的子序列,也就是说,k永远为1或2,我被提示里的k=3,4带偏了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
### 回答1: 我可以分享一种有效的训练计划,以达到codeforces橙名。首先,建立一个长期的训练计划,每周至少完成3-4个题目,把每个题目的解题过程都认真的思考一遍,确保理解每一步的思路。建议每隔一段时间,做一次综合练习,以更好地检验自己的知识水平。此外,参加竞赛也可以加深对算法的理解,从而提升解题能力。 ### 回答2: 想要在Codeforces达到橙名的水平,需要进行系统性的训练,并掌握一定的算法和编程技巧。以下是一个可能的训练计划: 1. 学习基础知识:首先,建议你系统地学习计算机科学的基础知识,包括数据结构和算法。这可以帮助你理解不同问题的解决方案,并优化代码的执行效率。 2. 解决题目:开始刷题是锻炼算法和编码能力的关键。选择一些简单的题目,如Codeforces的Div2 A、B级题目,按难度逐渐增加。通过不断解决题目,你将熟悉各种算法,并提高编写清晰、高效代码的能力。 3. 学习算法:学习和掌握一些常用算法,如贪心、动态规划、图论等。理解算法原理,分析其时间和空间复杂度,并通过练习将其应用于具体的问题。 4. 参加比赛:参加Codeforces的比赛是衡量自己水平的好方法。开始参加Div2级别的比赛,并争取在中等难度的题目上取得好成绩。逐渐挑战3级、4级比赛,尽量与更强的选手竞争,以提高自己的水平。 5. 反思和学习:每次比赛后,对自己的解题过程进行反思和总结。分析解错的原因,学习其他参赛选手的思考方式和技巧。通过学习他人的优秀代码和解题思路,不断提升自己的编码能力。 6. 练习编码技巧:除了算法,熟练掌握编码技巧也非常重要。学习并应用一些常用的数据结构和STL库,如数组、链表、栈、队列等。多写一些小项目或练习题,锻炼自己的编码能力。 7. 时间管理:合理安排学习和练习的时间。每天保持一定时间的刷题和学习,坚持养成好的学习习惯。同时,在比赛中也要控制好时间,并尽量在限定时间内完成题目。 总之,达到Codeforces橙名的水平需要长期的训练和不断的学习。通过刷题、学习算法和编码技巧、参加比赛以及反思总结,你可以逐渐提升自己的水平,并取得理想的成绩。记住,坚持和持续学习是达到目标的关键。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值