首页 > 其他分享 >CodeForces 1992E Novice's Mistake

CodeForces 1992E Novice's Mistake

时间:2024-07-16 13:08:14浏览次数:6  
标签:string ll Novice CodeForces 1992E include Mistake

题目链接:CodeForces 1992E 【Novice's Mistake】



思路

       直接对a,b枚举肯定会超时,因为a,b数数字过大,但是通过结果a * n - b可以发现结果最多为6位数,所以对结果的位数进行枚举,然后枚举a,来计算出b并判断是否符合题意,同时需要去掉b不符合题目的范围的情况。


代码

#include <functional>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#define ll long long
const int N = 50090 + 10;

struct ab {
  ll a, b;
} res[N];

void solve(){
  ll n, a, b, ans = 1;
  cin >> n;
  string s1 = to_string(n);
  for (int i = 2; i <= 10000; i++) {
    string s2 = "";
    while (s2.length() <= 10)
      s2 += s1;

    for (int j = 1; j <= 6; j++) {
      ll b = s1.size() * i - j;
      if (b < 1 || b > min(10000ll, n * i))
        continue;
      
      if (to_string(i * n - b) == s2.substr(0, j)) {
        res[ans++] = {i, b};
	  }
	}
  }
  cout << ans - 1 << endl;
  for (int i = 1; i < ans; i++) {
    cout << res[i].a << " " << res[i].b << endl;
  }
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

标签:string,ll,Novice,CodeForces,1992E,include,Mistake
From: https://www.cnblogs.com/againss/p/18305010

相关文章

  • CodeForces - 1485F
    题目大意给定数组\(b\),求有多少\(a\)数组满足\(a_i=b_i\or\\sum\limits_{k=1}^ia_k=b_i\)。分析既然有前缀和,不妨将前缀和计入状态中,设\(dp_{i,j}\)为前\(i\)个前缀和为\(j\)的方案数。考虑两种条件的转移方程。若选第一种,有\(dp_{i,j}=dp_{i-1,j-b_i}\)若......
  • Codeforces Round #956 (Div. 2) and ByteRace 2024
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1983孩子们我回来了。这场实在是太对胃口,vp不到1h就4题了之后EF也口出来了,然而赛时睡大觉去了没打真是亏死。感觉自己的文字能力已经很牛逼了,不需要再多练了,以后的题解都会写得简略些。A......
  • codeforces 1980 E. Permutation of Rows and Columns
    题目链接https://codeforces.com/problemset/problem/1980/E题意共输入\(T\)组测试用例,每组测试用例第一行输入两个整数\(n,m\),分别代表输入的数据的行数和列数,其中\(n*m\leq2*10^5\)。接下来输入两个\(n\)行\(m\)列的矩阵\(a,b\),对于每个矩阵中的元素\(x_{i,j}\)都是......
  • Solution - Codeforces 1311E Construct the Binary Tree
    先去考虑找一下无解条件。首先就是有\(d\)关于\(n\)的下界\(L\),就是弄成一颗完全二叉树的答案。其次有\(d\)关于\(n\)的上界\(R\),就是成一条链的样子。首先当\(d<L\)或\(R<d\)时显然无解。对于\(L\led\leR\)又如何去判定。能发现没有一个比较好的判定......
  • 题解:CodeForces 346A Alice and Bob[博弈/数论]
    CodeForces346AA.AliceandBobtimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputItissoboringinthesummerholiday,isn'tit?SoAliceandBobhaveinventedanewgametoplay.Therulesa......
  • 题解:CodeForces 843A Sorting by Subsequences[模拟/排序]
    CodeForces843AA.SortingbySubsequencestimelimitpertest:1secondmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputYouaregivenasequence\(a_1, a_2, ..., a_n\)consistingofdifferentintegers.Itisrequiredtos......
  • 题解:CodeForces 618C Constellation[贪心/模拟]
    CodeForces618CC.Constellationtimelimitpertest:2secondsmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputCatNokuhasobtainedamapofthenightsky.Onthismap,hefoundaconstellationwithnstarsnumberedfrom......
  • 题解:CodeForces 835 D Palindromic characteristics[区间dp/马拉车Manacher]
    CodeForces835DD.Palindromiccharacteristicstimelimitpertest:3secondsmemorylimitpertest:256megabytes*inputstandardinputoutputstandardoutputPalindromiccharacteristicsofstring\(s\)withlength\(|s|\)isasequenceof\(|s|\)in......
  • 题解:CodeForces 1019 A Elections[贪心/三分]
    CodeForces1019AA.Electionstimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsyouknow,majorityofstudentsandteachersofSummerInformaticsSchoolliveinBerlandforthemostparto......
  • 题解:CodeForces 1511 C Yet Another Card Deck[暴力/模拟]
    CodeForces1511CC.YetAnotherCardDeckDescriptionYouhaveacarddeckof\(n\)cards,numberedfromtoptobottom,i. e.thetopcardhasindex\(1\)andbottomcard —index\(n\).Eachcardhasitscolor:the\(i\)-thcardhascolor\(a_i\......