Contest2240 - 抗击疫情,从我做起--大中小学生联合训练赛第四十九场

问题 L: Handstand 2
时间限制: 1 Sec 内存限制: 128 MB
[提交] [状态]

题目描述

Given is a positive integer N.Find the number of pairs (A,B) of positive integers not greater than
N that satisfy the following condition:
·When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.
Constraints
·1≤N≤2×105
·All values in input are integers.

输入

Input is given from Standard Input in the following format:

N

输出

Print the answer.

样例输入 Copy

【样例1】
25
【样例2】
1
【样例3】
100
【样例4】
2020
【样例5】
200000

样例输出 Copy

【样例1】
17
【样例2】
1
【样例3】
108
【样例4】
40812
【样例5】
400000008

提示

样例1解释
The following 17 pairs satisfy the condition: (1,1), (1,11), (2,2), (2,22), (3,3), (4,4), (5,5),
(6,6), (7,7), (8,8), (9,9), (11,1), (11,11), (12,21), (21,12), (22,2), and (22,22).

  • 题意就是找到两个数满足一个数的第一位是另一个数的最后一位,另一个数的第一位是这个数的最后一位;

  • 思路分析:遍历每个数 得出首位和末尾的数字,然后模拟组合。
    代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn=2e6+1010;
#define inf 0x3f3f3f3f
const int mod=1e9+7;

ll f[maxn],a[maxn],b[maxn],n,m,t,flag,temp,sum,x,y;
string str,s;
ll dp[100][100];

ll find(ll x){//首位的大小 
    while(x){
        if(x/10==0){
            return x;
        }
        x/=10;
    }
}

ll gcd(ll a,ll b){
	while(b){
		ll temp=a%b;
		a=b;
		b=temp;
	}
	return a;
}

int main()
{
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		dp[find(i)][i%10]++;//首位末尾大小 
	}
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			sum+=dp[i][j]*dp[j][i];//表示可能性
	
	cout<<sum<<endl; 
    return 0;
}
全部评论

相关推荐

2025-12-08 16:04
门头沟学院 Java
本人本科末9,今年大三。大一大二一直玩,什么都没学到,在大学混日子混了两年,每天不是在打农就是在steam。大三开学时一个和自己玩的好的同学去实习了,才发现自己白白浪费了两年的时间,如果真不冲一下就真去京东,阿里,美团送外卖了今年9月份开始学Java,一开始一直跟着黑马视频看,后面发现看视频效率太低了,时间根本不够,就开始主要看文档和看书了。这几个月一直在学,真的尽力了,希望暑期前能找一份好点的实习。我简历上面的项目大多没有指标,但是实际上我是真没多少时间去做项目,我基本主要是动手只做了外卖和天机,黑马点评和12306我都是只是看了项目。主要是自己的时间真的不多,但是这样子自己的代码能力确实比较差。而且自己也没有做过实际的工程,我顶多用jmeter测试一下接口tps啥的,比如使用Redis管道提升了一点性能,减少Redis交互,这种值得写上去吗?需不需要具体到某些数字求求各位佬给一些建议,看看简历怎么优化?项目介绍是不是不够详细?没有具体到业务方面。项目会不会提到大致实现原理导致面试官一看简历就知道怎么实现就没有问的欲望?专业技能一些字段是不是要加粗,是不是写太啰嗦了?有没有必要压缩内容变成一页?两页的话是不是都要把两页填地满满的。
给秋招一个交代:一页简历最好,网上做的项目放面试官眼里都是玩具,简历上不需要强调有什么难点,记住就行防止真的问。然后背八股,多投多面试就行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务