USCAO section1.2 Palindromic Squares

USACO section 3.4 Closed Fences(计算几何+叉积+二分) Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N corners (3 i, yi}, i in (1..N). Every pair of adjacent vertices defines a side of the fence. 阅读详情
 
                                                     Palindromic Squares
Rob Kolstad

Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.

Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters 'A', 'B', and so on to represent the digits 10, 11, and so on.

Print both the number and its square in base B.

PROGRAM NAME: palsquare

INPUT FORMAT

A single line with B, the base (specified in base 10).

SAMPLE INPUT (file palsquare.in)

10

OUTPUT FORMAT

Lines with two integers represented in base B. The first integer is the number whose square is palindromic; the second integer is the square itself.

SAMPLE OUTPUT (file palsquare.out)

1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696

 

回文判断处理,注意细节,还是蛮好A的,具体看代码,还是挺容易懂的吧(我这代码源先在写的时候就被我一哥们批的体无完肤,不过个人认为还好)

 

/*
ID:nealgav1
PROG:palsquare
LANG:C++
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1234
using namespace std;
struct A
{
  int star[N];
  int sq[N];
  char s[N][102];
  char e[N][102];
  int shu;
};
const char b[22]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L'};
struct A pa[30];
struct A help;
void creat()
{
  for(int i=1;i<=300;i++)
  {
    help.star[i]=i;
    help.sq[i]=i*i;
  }
}
void transfor(int n)
{

  for(int j=1;j<=300;j++)
  {
    int i=0;
    while(help.sq[j])
   {
    help.e[j][i++]=b[help.sq[j]%n];
    help.sq[j]/=n;
   }
   help.e[j][i]='\0';
   int ii=0;
    while(help.star[j])
    {
      help.s[j][ii++]=b[help.star[j]%n];
      help.star[j]/=n;
    }
    help.s[j][ii]='\0';
  }
}
void charge(int n)
{
  int l,r,k,len;
  bool flag;
  k=0;
  for(int j=1;j<=300;j++)
  {
    flag=0;

    len=strlen(help.e[j]);
    l=0;r=len-1;
    while(l<r)
    {
      if(help.e[j][l]==help.e[j][r])
      {
        l++;r--;
      }
      else
      {
        flag=1;
        break;
      }
    }
    if(!flag)
    {
      strcpy(pa[n].e[++k],help.e[j]);
      strcpy(pa[n].s[k],help.s[j]);
    }
  }
  pa[n].shu=k;
}
void ok()
{
  for(int i=2;i<=20;i++)
  {
    creat();
    transfor(i);
    charge(i);
  }
}
int main()
{
  int m;
  ok();
  freopen("palsquare.in","r",stdin);
  freopen("palsquare.out","w",stdout);
  while(scanf("%d",&m)!=EOF)
  {
    for(int i=1;i<=pa[m].shu;i++)
    {
      for(int j=strlen(pa[m].s[i])-1;j>=0;j--)
      printf("%c",pa[m].s[i][j]);
      printf(" %s\n",pa[m].e[i]);
    }
  }
}

 
USER: Neal Gavin Gavin [nealgav1]
TASK: palsquare
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.011 secs, 11264 KB]
   Test 2: TEST OK [0.011 secs, 11264 KB]
   Test 3: TEST OK [0.302 secs, 11264 KB]
   Test 4: TEST OK [0.000 secs, 11264 KB]
   Test 5: TEST OK [0.000 secs, 11264 KB]
   Test 6: TEST OK [0.011 secs, 11264 KB]
   Test 7: TEST OK [0.011 secs, 11264 KB]
   Test 8: TEST OK [0.011 secs, 11264 KB]

All tests OK.

YOUR PROGRAM ('palsquare') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
10
------- test 2 ----
2
------- test 3 ----
5
------- test 4 ----
11
------- test 5 ----
15
------- test 6 ----
18
------- test 7 ----
20
------- test 8 ----
3
Keep up the good work!
Palindromic Squares
Russ Cox

We generate all the squares from 1 to 300 and check to see which are palindromes.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <math.h>

/* is string s a palindrome? */
int
ispal(char *s)
{
    char *t;

    t = s+strlen(s)-1;
    for(t=s+strlen(s)-1; s<t; s++, t--)
    	if(*s != *t)
	    return 0;

    return 1;
}

/* put the base b representation of n into s: 0 is represented by "" */

void
numbconv(char *s, int n, int b)
{
    int len;

    if(n == 0) {
	strcpy(s, "");
	return;
    }

    /* figure out first n-1 digits */
    numbconv(s, n/b, b);

    /* add last digit */
    len = strlen(s);
    s[len] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n%b];
    s[len+1] = '\0';
}

void
main(void)
{
    char s[20];
    char t[20];
    int i, base;
    FILE *fin, *fout;

    fin = fopen("palsquare.in", "r");
    fout = fopen("palsquare.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d", &base);
    for(i=1; i <= 300; i++) {
	numbconv(s, i*i, base);
	if(ispal(s)) {
	    numbconv(t, i, base);
	    fprintf(fout, "%s %s\n", t, s);
	}
    }
    exit(0);
}


Thanks for your submission!
HFSS - 双频微带天线设计与仿真 一、设计指标 中心频率:1.9GHz、2.45GHz 匹配情况:中心频率处S11S_{11}S11​参数小于-20dB 介质板厚度:1.6mm 介质板介电常数:3.8 馈电方式:50Ω\OmegaΩ同轴线馈电 二、双频微带天线 获得双频工作的一种最简单的方法是辐射贴片的长度对应-一个频率谐振,其宽度对应另一个频率谐振,然后从对角线的一角馈电,就能使同一个辐射贴片工作于两个频率上。其结构如下图所示。 从图中可以得知,x轴上的A点(x,0)为激发TM10_{10}10​模式的50Ω\OmegaΩ馈电点,由 阅读详情

相关推荐

基于STM32与FPGA Cyclone IV的FSMC高速数据通信实战解析

本文详细解析了基于STM32的FSMC接口与FPGA Cyclone IV实现高速并行数据通信的实战方案。通过将FPGA模拟为SRAM设备,构建了MCU与FPGA之间的高速数据通道,并深入探讨了硬件连接、STM32软件配置、FPGA逻辑设计及性能优化等关键步骤,为图像处理、高速采集等需要大数据量交换的嵌入式应用提供了稳定高效的通信解决方案。

swift5iosmith的博客 307

经典进制转换——USACO Palindromic Squares

Description Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N...

weixin_30267785的博客 179

【5G演进】4G到5G演进之网络架构与协议栈

4G到5G演进之网络架构与协议栈

Learning makes me happy (0^◇^0) 5551

USACO基础第七题Palindromic Squares

  USACO很多函数都限制掉了,不让用,所以很多库函数都会WA,后面找的模板和库函数都用不上了,逼我直接写了个最脑残的程序,输入输出还输反了。无限wa。总之要小心,库函数不要随便用。特别是比较生疏的,wa的可能性比较大。可能网站的目的就是让自己从头开始写,什么都得自己写。比如itoa,goto等都不提供。纯粹的编码。strlen都不让用。   因为这个题是处理数,所以平时那些对付字符串的函数都...

weixin_30516243的博客 131

XC7Z010-1CLG400C开发板ADC引脚配置全攻略(附完整引脚列表)

本文详细解析了XC7Z010-1CLG400C开发板的ADC引脚配置方法,涵盖XADC模块基础、CLG400封装的引脚布局、硬件设计规范及Vivado工程配置实战。特别提供了完整的引脚列表和性能优化技巧,帮助开发者高效实现模拟信号采集,适用于Zynq-7000系列开发。

weixin_29188043的博客 479

Triton算子开发与量化实践:从入门到vLLM接入

Triton是高效开发高性能深度学习算子的开源工具,用接近Python的语法实现接近CUDA的性能,支持多硬件平台。它与量化结合可实现模型体积小、速度提升30%-2倍、显存节省的三重收益。虽vLLM等框架已内置主流量化算子,但在非NVIDIA硬件、特殊算法或极致性能场景下,自定义Triton量化算子仍具显著优势。通过注册机制接入vLLM,可灵活替换算子并优化推理性能,是突破算力瓶颈的关键能力。

Ven%的博客 46

Palindromic Squares

Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N &lt...

weixin_30378623的博客 174

Google Earth Engine(GEE)——使用归一化燃烧指数 (NBR) 绘制地表烧伤严重程度图

归一化燃烧指数(Normalized Burn Ratio, NBR)是一种遥感指标,用于评估野火或烧伤地面后的植被恢复情况。NBR能增强较大范围的火灾区域,如大于200公顷。它是通过比较远红外波段 (SWIR) 和近红外波段 (NIR) 的反射率来计算的。SWIR波段测量烧伤地面的反射率,NIR波段测量没有受到烧伤影响的植被的反射率。NBR的计算公式为:NBR =(NIR-SWIR)/(NIR + SWIR)。其中,NIR为近红外波段,SWIR为短波红外波段。

此星光明博客 3489

USACO Section 1.2 Palindromic Squares

给定基数B(2

YanLucyqi的博客 394

PCL RANSAC拟合分割多条直线【2027最新版】

使用RANSAC算法拟合分割多条直线,输出每一条直线的拟合参数到控制台,并保存直线点云到本地文件夹。博客长期更新,本文最新更新时间为:2026年12月2日。

点云侠的博客 7986

EtherCAT主站SOEM -- 1 -- SOEM之ethercattype.h文件分析

“ethercattype.h” 文件用于支持 EtherCAT 网络通信,提供了各种类型定义和宏,以便开发者更轻松地开发 EtherCAT 相关应用程序。这些定义包括数据类型、命令类型、状态类型和错误类型,以支持 EtherCAT 通信。根据具体应用需求,还可以调整一些超时和帧长度设置。这些定义用于处理函数调用的结果,如 EC_NOFRAME(没有帧返回)、EC_ERROR(一般错误)、EC_TIMEOUT(请求超时)等。这些定义用于处理 EtherCAT 命令,例如 EC_CMD_APRD(自动递增读取

常驻客栈的博客--嵌入式EtherCAT 2727

USCAO Section 1.2 Palindromic Squares

原题: Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome.Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 bas

qq_34407173的博客 318

MATLAB 基于深度学习的步态识别算法仿真

步态识别是一种通过分析人体行走方式来识别身份的技术。基于深度学习的步态识别算法利用卷积神经网络 (CNN) 提取步态特征,并通过分类器进行身份识别。基于深度学习的步态识别算法是实现身份识别的重要手段,具有广泛的应用前景。MATLAB 提供了丰富的工具和函数,可以方便地进行算法仿真和性能评估。

走向CTO的路上... 526

USACO section 3.1 Contact(AC自动机)

Contact IOI'98 The cows have developed a new interest in scanning the universe outside their farm with radiotelescopes. Recently, they noticed a very curious microwave pulsing emission sent right f

nealgavin的专栏 9384

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

USCAO section 1.3 Calf Flac

Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes

nealgavin的专栏 6656

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

USACO section 1.5 Checker Challenge(dfs深搜)

Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more tha

nealgavin的专栏 1924

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

USACO section 2.3 Longest Prefix(dp)

Longest Prefix IOI'96 The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in

nealgavin的专栏 1487

USACO section 2.4 Cow Tours(并查集+最短路)

Cow Tours Farmer John has a number of pastures on his farm. Cow paths connect some pastures with certain other pastures, forming a field. But, at the present time, you can find at least two pasture

nealgavin的专栏 1406

USACO section3.1 Shaping Regions(漂浮法)

Shaping Regions N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the s

nealgavin的专栏 1052

USACO section 2.2 Runaround Numbers

Runaround Numbers Runaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration: If you start

nealgavin的专栏 991

USACO section 3.1 Stamps(dp)

Stamps Given a set of N stamp values (e.g., {1 cent, 3 cents}) and an upper limit K to the number of stamps that can fit on an envelope, calculate the largest unbroken list of postages from 1 cent

nealgavin的专栏 980

USCAO section 4.1 Fence Loops(最短路,最小环,5级)

Fence Loops The fences that surround Farmer Brown's collection of pastures have gotten out of control. They are made up of straight segments from 1 through 200 feet long that join together only a

nealgavin的专栏 941

USACO section 1.5 Superprime Rib(深搜)

Superprime RibButchering Farmer John's cows always yields the best prime rib. You can tell prime ribs by looking at the digits lovingly stamped across them, one by one, by FJ and the USDA. Farmer John

nealgavin的专栏 938

USACO section 2.2 Party Lamps

Party Lamps IOI 98 To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored lamps numbered from 1 to N. The lamps are connected to four buttons: Button 1: Wh

nealgavin的专栏 914

USACO section 3.2 Spinning Wheels(模拟)

Spinning Wheels 1998 ACM NE Regionals Each of five opaque spinning wheels has one or more wedges cut out of its edges. These wedges must be aligned quickly and correctly. Each wheel also has an ali

nealgavin的专栏 875

USCAO section Mother's Milk(搜索)

Mother's Milk Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty

nealgavin的专栏 848
上一篇: hdu 1081 To The Max
下一篇: USCAO section 1.2 Dual Palindromes
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址