USCAO section1.3 Prime Cryptarithm(感觉思路挺好)

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. 阅读详情
Prime Cryptarithm

The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits {2,3,5,7} is selected, the cryptarithm is called a PRIME CRYPTARITHM.

      * * *
   x    * *
    -------
      * * *         <-- partial product 1
    * * *           <-- partial product 2
    -------
    * * * *
Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed.

Note that the 'partial products' are as taught in USA schools. The first partial product is the product of the final digit of the second number and the top number. The second partial product is the product of the first digit of the second number and the top number.

Write a program that will find all solutions to the cryptarithm above for any subset of digits from the set {1,2,3,4,5,6,7,8,9}.

PROGRAM NAME: crypt1

INPUT FORMAT

Line 1:N, the number of digits that will be used
Line 2:N space separated digits with which to solve the cryptarithm

SAMPLE INPUT (file crypt1.in)

5
2 3 4 6 8

OUTPUT FORMAT

A single line with the total number of unique solutions. Here is the single solution for the sample input:

      2 2 2
    x   2 2
     ------
      4 4 4
    4 4 4
  ---------
    4 8 8 4

SAMPLE OUTPUT (file crypt1.out)

1

解题思路:用一个五位数数组line[]来存两个乘数的所有可能性,在用一个charge[]数组存三个判断因子的所有可能性并标记(需注意三位数与四位数也要标记为不同,否则后面会出错,我就是这都标记为1后错了一次),而后遍历line[]的三个判断因子,成功则ANS(答案数)加一
如何去五位数:遍历全部五位数找出所有合题意的数。
两个乘数:一个是五位数前三个line[]/100:另一个是五位数后两个line[]%100;
 
 
 
/*
ID:nealgav1
PROG:crypt1
LANG:C++
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 123456
using namespace std;
int line[N];
int charge[N];
int ke;
int pan[12];
int main()
{
  freopen("crypt1.in","r",stdin);
  freopen("crypt1.out","w",stdout);
  int m;
  while(scanf("%d",&m)!=EOF)
  {
    int i;
   memset(pan,0,sizeof(pan));
    for(i=0;i<m;i++)
    {
      scanf("%d",&ke);
      pan[ke]=1;
    }
    int k;
    int M;
    bool flag;
    M=0;
    for(i=10000;i<100000;i++)
    {
      flag=1;
       int z=i;
      while(z)
      {
         k=z%10;
         if(!pan[k])
         {
           flag=0;
           break;
         }
         z/=10;
      }
      if(flag)
      line[M++]=i;
    }
   memset(charge,0,sizeof(charge));
    for(i=100;i<10000;i++)
    {
      flag=1;
      int z=i;
      while(z)
      {
         k=z%10;
         if(!pan[k])
         {
           flag=0;
           break;
         }
         z/=10;
      }
      if(flag)
      {
        if(i>1000)
        charge[i]=1;
        else
        charge[i]=2;
      }

    }
    int ans=0;
    int a,b,c;
    for(i=0;i<M;i++)
    {
      a=line[i]%100;
      line[i]/=100;
      b=a%10;
      c=a/10;
      a*=line[i];
      b*=line[i];
      c*=line[i];
      if(charge[a]==1&&charge[b]==2&&charge[c]==2)
      {
        ans++;
      }
    }
    printf("%d\n",ans);
  }
}

 
 
Prime Cryptarithm Russ Cox

The constraints of this problem are small enough that we can just try all possible products of 3 digit * 2 digit numbers, and look to see if all the correct digits are used.

The function "isgood" checks that a number is composed only of acceptable digits, and "isgoodprod" checks that all the lines of the multiplication are composed of acceptable digits.

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

int isgooddigit[10];	/* isgooddigit[d] is set if d is an acceptable digit
*/

/* check that every decimal digit in "n" is a good digit,
   and that it has the right number "d" of digits. */
int
isgood(int n, int d)
{
    if(n == 0)
		return 0;

    while(n) {
	if(!isgooddigit[n%10])
	    return 0;
	n /= 10;
        d--;
    }

    if( d == 0 )
       return 1;
    else
       return 0;
}

/* check that every product line in n * m is an okay number */
int
isgoodprod(int n, int m)
{
    if(!isgood(n,3) || !isgood(m,2) || !isgood(n*m,4))
	return 0;

    while(m) {
	if(!isgood(n*(m%10),3))
	    return 0;
	m /= 10;
    }
    return 1;
}

void
main(void)
{
    int i, j, n, nfound;
    FILE *fin, *fout;

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

    for(i=0; i<10; i++) {
        isgooddigit[i] = 0;
    }
    fscanf(fin, "%d", &n);
    for(i=0; i<n; i++) {
	fscanf(fin, "%d", &j);
	isgooddigit[j] = 1;
    }

   nfound = 0;
   for(i=100; i<1000; i++)
	for(j=10; j<100; j++)
	    if(isgoodprod(i, j))
		nfound++;

   fprintf(fout, "%d\n", nfound);
   exit(0);
}

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

Compiling...
Compile: OK

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

All tests OK.

Your program ('crypt1') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
5
2 3 4 6 8
------- test 2 ----
4
2 3 5 7
------- test 3 ----
1
1
------- test 4 ----
7
4 1 2 5 6 7 3
------- test 5 ----
8
9 1 7 3 5 4 6 8
------- test 6 ----
6
1 2 3 5 7 9
------- test 7 ----
9
1 2 3 4 5 6 7 8 9
Keep up the good work!

基于MATLAB的电池等效电路模型(ECM)仿真,用于分析电气行为和动态响应.zip 1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 立即下载

相关推荐

隔离型全桥LLC谐振变化器建模及参数设计资料【仿真+设计报告+计算书】

内容概要:本文档系统性地提供了隔离型全桥LLC谐振变换器的建模、仿真与参数设计全套技术资料,涵盖Simulink/Plecs仿真模型、详细设计报告及Mathcad计算书,内容涉及开环与闭环控制、软启动过程、恒压恒流双闭环竞争控制等多种工况。资料还拓展至多相交错LLC、双向CLLC拓扑以及V2G(Vehicle-to-Grid)电动汽车充放电等前沿应用场景,并融合状态估计算法(如卡尔曼滤波、扩展卡尔曼滤波、粒子滤波)与神经网络技术进行系统性能优化,配套PPT说明与高水平EI期刊复现案例,为电力电子领域的科研与工程设计提供完整的技术支撑; 适合人群:适用于电力电子、电气工程及其自动化等相关专业的高校研究生、科研人员,以及从事高频DC-DC变换器、新能源电源系统开发的工程师,具备扎实电路理论基础和Matlab/Simulink仿真能力者尤佳; 使用场景及目标:①支撑LLC谐振变换器相关的科研课题、学位论文或项目开发;②开展高频高效电源的参数设计、效率优化与动态响应分析;③学习并复现高水平期刊中先进的控制策略,如变频控制、混合移相控制及智能优化算法;④掌握Simulink/Matlab在电力电子系统建模、控制算法实现与状态估计中的综合应用; 阅读建议:建议结合仿真模型、Mathcad计算书与设计报告三位一体同步研习,重点理解主电路参数设计与闭环控制逻辑之间的耦合关系,优先运行典型算例并调试关键模块,有条件者可进一步推进至硬件原型验证,并积极探索状态估计与人工智能算法在电力系统动态建模中的融合应用。

USCAO-Section 1.3 Prime Cryptarithm

原题: The following cryptarithm is a multiplication problem that can be solved by substituting digits from a specified set of N digits into the positions marked with *. If the set of prime digits {2,3,

qq_34407173的博客 372

标准材质转物理材质 对应脚本:标准转物理材质转x.ms 一、插件用途 将 3ds Max 场景中的 StandardMaterial 标准材质转换为 PhysicalMaterial 物理材质

标准材质转物理材质 对应脚本:标准转物理材质转x.ms 一、插件用途 将 3ds Max 场景中的 StandardMaterial 标准材质转换为 PhysicalMaterial 物理材质,并递归处理 Multi/Sub 多维子材质及 Blend 混合材质中的标准材质。 二、转换内容 脚本尝试进行以下参数映射: - 漫反射颜色 → Physical Material 基础颜色。 - 漫反射贴图及启用状态 → 基础颜色贴图。 - 凹凸贴图、启用状态及强度 → 物理材质凹凸槽;强度会按脚本比例换算。 - Opacity 贴图 → 物理材质透明颜色贴图。 - 标准材质自发光颜色和强度 → 物理材质发光颜色和发光强度。 - 反射贴图强度 → 粗糙度的反向换算。 - Glossiness → Metalness 数值换算。 三、使用方法 1. 在 3ds Max 中运行脚本。 2. 出现“赵山河材质转换”小窗口。 3. 点击“标准材质转物理材质”。 4. 脚本扫描整个场景的材质库,并将场景物体所使用的标准材质转换为物理材质。 5. 转换完成后刷新视口。 四、处理范围 - 不是只处理当前选择对象,而是扫描整个场景的材质库。 - 对 Multi/Sub 材质递归转换其中的标准材质子项。 - 对 Blend 材质递归转换 map1、map2 中的材质。 - 非 StandardMaterial 的材质会按脚本逻辑保留,不会强制全部转成 PhysicalMaterial。 五、注意事项 - 这是参数近似转换,不是渲染结果完全一致的材质转换。 - 标准材质中的高光、反射、透明度、特殊贴图和高级参数不一定有一一对应关系。 - 脚本把 Glossiness 映射到 Metalness,属于

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

UniApp实战:5分钟搞定后台持续定位与轨迹实时更新(附完整代码)

本文详细介绍了在UniApp中实现后台持续定位与动态轨迹地图系统的完整方案。针对物流配送、运动健身等场景,文章深入讲解了权限申请、坐标系选择、定位防抖优化、地图轨迹线(polyline)实时绘制等核心步骤,并提供了可复用的完整代码,帮助开发者高效解决App切后台定位停止、轨迹漂移等常见难题。

weixin_29266679的博客 483

知识图谱初步学习(一)——本体+Protege新手学习

文章目录前言(本体详解)1.本体概念2.本体分类3.本体组成4.本体构建方法一、protege简介二、软件使用步骤1.安装2.使用三、问题解决方案汇总 前言(本体详解) 在开始学习知识图谱的过程中,首先就是要了解什么是本体(ontology)。 1.本体概念 本体的概念最初源自于哲学领域,在哲学中的定义为“对世界上客观事物的系统描述,即存在论”。哲学中的本体关心的是客观现实的抽象本质。而在计算机领域,本体是可以在语义的层次上来对知识进行描述,可以看做是某一个领域知识的通用模型。 本体是从客观世界中抽象出来

qq_43654669的博客 3万+

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

别再只调PID了!手把手教你从LC谐振到检波,搞定STM32智能车电磁循迹硬件电路

本文深入解析STM32智能车电磁循迹硬件电路设计,从LC谐振选频到数字信号处理,提供完整的信号链路设计要点与实战技巧。通过优化电磁杆布局和信号放大电路,显著提升赛道位置检测精度,误差可控制在±0.5cm以内,为智能车竞赛提供可靠硬件支持。

weixin_29220405的博客 263

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

Sony DPT RP1/CP1破解攻略

前言 自己有一台Sony DPT CP1和一台kindle,两个都已经用了很多年。直到最近发现微信读书上经常可以找到一些免费而且不错的书,所以就萌生了在两台机器上使用微信读书的想法。kindle比较容易实现,直接打开内置浏览器,进入微信读书网页版就行了,而Sony的电纸书则只能通过破解+安装微信读书的方式实现。大概弄了两三个小时吧,也遇到了一些问题,所以这里记录一下整个过程,希望能方便后来的使用者。 首先感谢HappyZ, osc_t5nbj8ds。前者是提供公开破解的方法的大神,后者则是解决了我遇到的问题

weixin_43467572的博客 1万+

【RDMA】13. RDMA之用户态与内核态交互

原文:https://zhuanlan.zhihu.com/p/346708569 在“RDMA之Verbs”一文中我们说道,Verbs API分为用户态和内核态,分别以ibv_和ib_作为前缀。RDMA技术的最大的优势就在于用户态可以绕过内核,直接控制硬件收发数据,减少了系统调用和内存拷贝次数,所以大部分的RDMA应用都是用户态应用,即使用以ibv_为前缀的用户态Verbs API。 但是并非所有的用户态Verbs API都可以完全绕开内核,本文中我来讲解一下哪些API依赖于内核RDMA子系统(包括驱

我的笔记本 4285

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

FFMPEG音频开发: Linux下采集摄像头(使用V4L2框架)数据录制成MP4视频保存到本地

一、环境介绍 操作系统介绍:ubuntu 18.04 FFMPEG版本: 4.4.2 摄像头: USB摄像头、虚拟机挂载本机自带摄像头 二、FFMPEG与X264下载编译 X264下载地址: http://www.videolan.org/developers/x264.html FFMPEG下载地址:https://ffmpeg.org/download.html Yasm ...

8871

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

k230 +canMV+ LVGL控件 仿手表表盘触摸屏滚动、选中后弹窗效果完整示例程序

现在智能手表用的越来越多,其交互方式比较有特点,现在k230开发板上,基于LVGL(Light and Versatile Graphics Library)编写一个嵌入式GUI应用程序,使用LVGL配合触摸屏实现模仿智能手表的表盘滚动效果,实际效果如下:程序使用LVGL图形库和MediaManager程序,创建带有触摸屏交互的GUI应用。程序主要功能包括显示初始化、LVGL初始化、创建GUI界面(包含一个可滚动的按钮列表,每个按钮点击会弹出消息框),以及处理触摸屏输入。

weixin_47446386的博客 1175

【人工智能之深度学习】12. BERT微调实战:医疗文本分类的领域自适应技巧与工业级实现

摘要:医疗文本分类是自然语言处理在医疗健康领域的核心应用,可辅助疾病诊断、病历结构化和医疗质量监控。然而,医疗文本的专业术语密集、实体关系复杂及数据长尾分布等特性,导致通用BERT模型性能受限。本文系统阐述医疗文本分类的领域自适应技术,从理论原理到工业级实现展开全流程讲解。首先分析医疗文本的独特属性及技术挑战;随后详解领域继续预训练、适配器微调、对抗训练等核心技术的数学原理;构建包含数据预处理、模型优化、隐私保护的完整实战架构;通过疾病分类、情感分析、事件检测三大案例验证技术有效性。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1004

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

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

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

USACO section 3.2 Feed Ratios(高斯定理)

Feed Ratios 1998 ACM Finals, Dan Adkins Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of th

nealgavin的专栏 803
上一篇: USCAO section 1.3 Calf Flac
下一篇: USCAO section 1.4 Packing Rectangles
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值