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!
YOLOv11改进 | Conv/卷积篇 | 利用Hype-YOLO提出MANet增强YOLOv11特征提取能力 本文给大家带来的最新改进机制是由Hype-YOLO提出的MANet结构,其是一种C3、C2f、C3k2的升级版,用于增强特征提取能力。MANet可以理解为C2f的升级版,其整合了DSConv和C2f结构,这些模块的组合使得信息流动更加丰富,有助于在训练过程中提高梯度流动,从而增加基础特征的语义深度。官方发布的数据中HypeYOLO的精度是高于YOLOv11的,本文内容包含MAnet替换C3k2的教程以及原理介绍。欢迎大家订阅我的专栏一起学习YOLO,购买专栏读者联系读者入群获取进阶项目文件! 阅读详情

相关推荐

【全新官方接口】php检测微信域名拦截,检测微信域名被封

你的域名在微信被拦截的3种常见情况 1、域名因违规或有风险被拦截(红色拦截) 2、类似taobao.com,douyin.com这种的恶意竞争式拦截,淘宝、抖音等微信的竞争对手一般都是白色拦截(白色拦截) 3、有一个中间页的拦截,需要多次点击按钮才可以跳转到你的域名的,多是一些新型域名后缀,例如.top .xyz .link后缀,这种情况,备案后可以解决(备案拦截) 通过php get_headers()函数就可以分析到结果 这个下标为6是一个URL,在微信访问后正是这个讨厌的页面! 如果切换为

TANKING,开源开发者! 2875

USACO基础第七题Palindromic Squares

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

weixin_30516243的博客 130

学习海康VisionMaster之表面缺陷滤波

本文介绍了VisionMaster中表面缺陷滤波技术的应用。该技术通过数学变换抑制背景干扰、增强缺陷特征,适用于电池铝壳、垫圈/螺丝等无纹理背景的表面缺陷检测(划痕、凹坑、异物等)。操作流程包括:图像导入、轮廓定位、位置修正、参数设置(重点讲解滤波核尺寸/数量/标准差等关键参数的调整策略)。文章通过案例演示了如何通过多方向滤波响应识别表面划伤,并指出需结合blob分析进一步优化检测结果。该技术对工业质检具有实用价值,参数设置需结合缺陷特征与背景特性灵活调整。

yuhouxiyang的专栏 2828

USACO Section 1.2 Palindromic Squares

给定基数B(2

YanLucyqi的博客 393

MPC-CBF 控制原理详解

假设系统满足如下离散时间动力学模型xt1fxtutxt∈Xut∈Uxt1​fxt​ut​xt​∈Xut​∈Uxtx_txt​:状态变量,定义域为可行状态集X⊆RnX⊆Rnutu_tut​:控制输入,定义域为控制约束集U⊆RmU⊆Rm系统需满足安全约束,由如下控制障碍函数(CBF)hX→RhX→RCx∈X∣hx≥0C:=x∈X∣hx≥。

m0_54691290的博客 1179

微信小程序 - 最新详细实现调起手机摄像头拍摄身份证人像面和国徽面取景框功能,在拍照相机上增加身份证证件照的轮廓或自定义文字,支持替换扫描拍摄辅助线图片及文本,小程序实现拍照身份证时带取景轮廓框拍摄!

微信小程序,身份证,证件照,人像,证件照提示框模板,vue身份证拍照框,摄像机相机里有引导内容,取景框拍摄,微信小程序实现拍照界面自定义实现,自拍人相框拍摄,取景框,户口簿取景框,画布指定区域生成图片,微信小程序身份证正反面拍照如何加入辅助图片引导照片,身份证取景框拍摄,服务器,上传,正反面,调起手机摄像头: 拍摄身份证的正反面,自定义身份证取景框,在相机上绘制 “身份证轮廓“ 与提示文字,拍摄身份证时出现人像框怎么实现,在相机上增加图片和文字,微信小程序怎么给调起的相机加入自定义图片,小程序实现给相机上面

🏆 前端领域优质创作者 3404

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的博客 173

PreScan快速入门到精通第二十一讲驾驶员模型之驾驶员在环

请注意,操纵杆的输出角度是以度为单位的,而方向盘执行器希望其输入是以弧度为单位的。当选择一个支持的方向盘时,PreScan会自动将按钮映射到正确的功能上(如换挡),并设置轴的正确范围(如转向角度)。该系统中的所有其他组件都是为了提供正确的按钮映射,并为所选的方向盘设置正确的范围。对于每一个额外连接的控制器,它们的ID会增加一个,例如第二个控制器的设备ID为1,第三个控制器的设备ID为2,等等。由于所有的方向盘最初放在编译表上的设备ID都是0,所以用户应该先进行正确的调整,将每个控制器设置为正确的设备ID。.

小明师兄的博客 1423

经典进制转换——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的博客 178

19、时间触发通信与时间触发以太网技术解析

本文深入解析了时间触发通信和时间触发以太网(TTEthernet)技术,涵盖了其在实时系统中的应用,特别是安全关键领域如航空航天。文章详细介绍了TTEthernet的通信服务、协议参数化、时钟同步机制、诊断服务、故障隔离方法以及验证工作,并通过示例配置展示了其灵活性和可扩展性。TTEthernet通过引入确定性时间触发通信范式,在同一物理网络上实现了时间触发、速率受限和尽力而为三种流量类别的集成,为分布式实时系统提供了高可靠性和实时性保障。

efc12345678的博客 115

复现《水化硅铝酸钙微结构和性能的分子动力学模拟研究》的分子动力学模拟

本文详细复现了杨军博士论文中关于水化硅铝酸钙(C-A-S-H)凝胶的分子动力学模拟方法。研究内容包括:1)基于11Å Tobermorite构建C-A-S-H分子模型,通过缺陷引入和Al掺杂调节Ca/Si比;2)使用ReaxFF力场模拟交联C-A-S-H的结构与力学性能;3)采用ClayFF力场研究纳米孔道中水和离子传输行为。研究提供了完整的LAMMPS输入脚本、Python分析代码和力场参数设置,为水泥基材料纳米尺度模拟提供可复现的技术方案。

huanghm88的专栏 105

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的博客 317

Unity零基础到进阶 ☀️| Unity中的 GC及优化 超级全面解析 ☆(ゝω・)v 建议收藏!

介绍: 在游戏运行的时候,数据主要存储在内存中,当游戏的数据在不需要的时候,存储当前数据的内存就可以被回收以再次使用。内存垃圾是指当前废弃数据所占用的内存,垃圾回收(GC)是指将废弃的内存重新回收再次使用的过程。 Unity中将垃圾回收当作内存管理的一部分,如果游戏中废弃数据占用内存较大,则游戏的性能会受到极大影响,此时垃圾回收会成为游戏性能的一大障碍点。 本文我们主要学习垃圾回收的机制,垃圾回收如何被触发以及如何提GC收效率来提高游戏的性能。 Unity内存管理机制简介 要想了解垃圾回收如何工作以及何时被

努力前行,总会成为自己心中的那道光 6万+

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

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

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

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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的专栏 1923

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

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的专栏 1486

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的专栏 1405

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的专栏 989

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的专栏 937

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的专栏 913

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的专栏 847
上一篇: 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、付费专栏及课程。

余额充值