POJ 2115 C Looooops

【代码超详解】POJ 2115 C Looooops(扩展欧几里得算法,0 ms) 一、题目描述 二、算法分析说明与代码编写指导 设要经过 x 次循环才可以跳出循环体,则有 a + cx ≡ b (% 2^k) 设 m = 2^k,则上式可转化为:cx - 2^k · y = b - a。 套用扩展欧几里得算法并将 x 调整为最小正整数解即为答案。如果 gcd(c, -2^k) 不能整除 (b - a) 则无解。 三、AC 代码(0 ms) 尝试提交时发现,无论是 cmath... 阅读详情

http://poj.org/problem?id=2115


推出同余方程:C*x  - 2^k*y = B -A直接使用扩展gcd求解!

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

LL exGcd(LL a, LL b, LL &x, LL &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    LL gcd = exGcd(b, a%b, y, x);
    y -= (a/b)*x;
    return gcd;
}

int main(){
    LL A,B,C,k;
    while(scanf("%lld%lld%lld%lld", &A,&B,&C,&k) == 4){
        if(!A && !B && !C && !k)    break;
        if(C == 0){
            if(A == B)  cout << "0" << endl;
            else cout << "FOREVER" << endl;
            continue;
        }
        LL a = C, b = -(1ll << k), c = B - A, x, y;
        LL gcd = exGcd(a, b, x, y);
        if(c % gcd){
            cout << "FOREVER" << endl;
            continue;
        }
        x *= c/gcd;
        if(b / gcd < 0) b = -b;
        x %= b/gcd;
        while(x < 0)    x += b/gcd;
        cout << x << endl;
    }    
    //system("pause");
    return 0;
}


YOLOv8首发优化:遥感目标检测 | 专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块,解决低空间分辨率、传感器噪声、目标模糊、低光照退化和部分遮挡等限制 一种轻量级网络,其创新性地整合了专为低质量遥感图像设计的边缘 - 高斯聚合(EGA)模块。 阅读详情

相关推荐

Windows下OpenMBEE项目MMS部署失败经历及改正

在Github里找到了上面的第一份文档,下载了MMS源代码(不知道为什么这个代码跟上面操作克隆得到的MMS代码不一样?好像是因为Gradle的版本问题,我本地之前已经安装过7.6.4的Gradle了,于是我找到gradle-wrapper.properties文件。后面在VScode中运行了一下依然是报这个错误,我在VScode终端直接执行。不知道为什么依然没什么用。打开“Windows PowerShell”。(如果是第一次运行它,将看到更长的输出)导航到要克隆存储库的文件夹,例如,

Yo_lan_da的博客 1872

【poj 2115】 C Looooops 【CTU Open 2004】

Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which starts by setting variable to

TLECODE的博客 742

【大模型】DeepSeek 高级提示词技巧使用详解

DeepSeek 高级提示词技巧使用详解

congge 1万+

[POJ2115] C Looooops

题目描述对于循环语句: for(variable=A;variable!=B;variable+=C)statement; 已知所有的数均要mod 2^k((即0 <= x < 2^k,1 <= k <= 32)),给出A,B,C和k的值,计算并输出statement执行的次数,如果为无限次,那么直接输出“FOREVER”。输入格式输入数据有多组,每组数据占一行,有四个整数A,B,C,k(0<=

Bill_Yang_2016的博客 455

Autosar配置——导入DBC后配置SecOC同步报文和同步请求报文

在Autosar中,安全性是一个重要的考虑因素,而SecOC(Secure On-Board Communication)是一种用于保护通信数据完整性和安全性的安全机制。在上述示例中,我们配置了同步报文和同步请求报文的属性。接下来,我们需要在Autosar中配置同步报文和同步请求报文。同步报文用于在通信双方之间同步SecOC状态,而同步请求报文用于请求SecOC的状态信息。通过以上配置,我们成功地导入了DBC文件,并在Autosar系统中配置了SecOC同步报文和同步请求报文。希望以上信息对您有所帮助!

CyberSphinx的博客 655

[P4V]Perforce(P4V)使用教程

1.前言 Perforce SCM System是一款构建于可伸缩客户/服务器结构之上的软件配置管理工具。仅仅应用TCP/IP,开发人员就能够通过多种Perforce客户端(几种平台的GUI、WEB、或命令行)访问Perforce服务器。Perforce能够被快速和容易地部署,即使对大型或分布式的站点,也只要求最小限度的管理。Perforce可以使用在50多个操作系统中,它包括版...

元直的博客 2万+

POJ2115 C Looooops

1 /* 2 POJ2115 C Looooops 3 http://poj.org/problem?id=2115 4 扩展欧几里得 5 题意:求x, s.t. (a+c*x)=b (mod 1<<k) 6 <=> c*x=b-a (mod 1<<k) 7 */ 8 #include &lt...

dianan9456的博客 135

DeerFlow 系列教程 第十四篇 | IM 渠道集成——让 DeerFlow 接入飞书、企微、Slack、Telegram

DeerFlow 系列教程 第十四篇本篇教程继续,全面剖析 DeerFlow 的 IM 渠道集成方案。我们将深入理解 Channel 抽象层设计、MessageBus 消息总线机制、ChannelManager 调度循环、四大 IM 平台(飞书、企业微信、Slack、Telegram)的适配实现,以及从 IM 消息到 Agent 响应再到 IM 回复的完整消息流转过程。

weixin_43674738的博客 421

【poj2115】C Looooops

Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which starts by setting variable to value...

lhh的博客 183

基于MATLAB的Hough变换指针式仪表识别

综上所述,本文介绍了如何使用MATLAB中的Hough变换算法来实现指针式仪表的自动识别和读数。通过图像预处理、Hough变换和直线提取,我们可以准确地检测指针的位置,并进一步进行仪表读数。本文将介绍如何使用MATLAB中的Hough变换算法来实现指针式仪表的自动识别和读数。在指针式仪表识别中,我们可以利用Hough变换来检测仪表盘上的指针。以上是基于MATLAB的Hough变换指针式仪表识别的详细步骤和源代码示例。根据指针在仪表盘上的位置,我们可以进行角度计算或使用其他技术来获取准确的读数。

techDM的博客 469

华东理工大学计算机预推免面试

华东理工大学预推免面试经验分享

D1379951481的博客 1408

POJ-2115 C Looooops

题意:就是求A+Cx=B(mod 1<<k)(式 1),的最小x的值。 思路:虽然脑袋很乱、不过还是水过。式 1可以转化为Cx-2^ky=B-A,然后直接带扩展欧几里得即可。有一个地方需注意,移位的时候1<<k是错的,写成1LL<<k就过了..... 题目链接:http://poj.org/problem?id=2115 View Cod...

bancaidun1539的博客 130

游戏引擎定制化:大厂如何玩转性能极限(大白话生动有趣版)

游戏大厂如何深度定制游戏引擎?本文系统解析了商业引擎的局限性及大厂定制化的核心诉求。主要内容包括: 大厂定制引擎的根本原因:性能瓶颈、差异化需求、自有生态整合等 主流引擎的优劣势对比及适用场景 定制化重点领域:渲染管线优化、物理系统重构、网络架构改造等 全流程定制方案:从需求分析到模块重构再到工具链开发 典型案例:如腾讯CF手游的渲染优化、原神的热更新系统等 文章指出,顶级游戏产品必须对引擎核心模块动刀,通过深度定制实现性能突破和创新功能开发。同时提供了风险规避建议和技术演进趋势,为游戏开发者提供了宝贵的实

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 640

C Looooops POJ - 2115

http://poj.org/problem?id=2115 拓展欧几里德裸题 以cc为a (1<<k)为b(bb-aa)为c 求(a*x)%b=c得最小非负整数解即可 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ty...

sunyutian1998的博客 201

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ_2115_C Looooops

同余方程

edward_108 276

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

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

POJ 2115C Looooops

http://poj.org/problem?id=2115 题目大意: 对于循环语句: for(int i = A; i != B; i += C) 已知i、A、B、C都是无符号整数类型,给出A、B、C、k的值,所有的数都不大于2^k,计算并输出循环语句的执行次数,如果为无限次,那么直接输出"FOREVER"。 设算法

Hytai的专栏 480

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

poj 2115 C Looooops

http://poj.org/problem?id=2115 C Looooops Time Limit:1000MS Memory Limit:65536K Total Submissions:34291 Accepted:9996 Description A Compiler Mystery: We are given ...

weixin_30764883的博客 111

poj 2115C Looooops

题目:http://poj.org/problem?id=2115; 题意:给出A,B,C经过多少次循环能结束,不能则输出FOREVER,且本题所有数值在2^k内; 分析:不难看出本题意图为求解A+c*x=b(mod 2^k)(由于三个横线不好打就用等号代替),显然是求解一次同余方程的最小值,采用扩展欧几里得算法解答; 代码: #include #include #include #

北门的智慧 561

POJ 2115, C Looooops

Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 6358Accepted: 1384 DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; varia...

weixin_34273046的博客 226

Poj-2115 C Looooops

[题解]: 拓展欧几里得求解一元线性同一方程模板题,刚开始学,比着解析求出了方程的一组解,想着要怎么求出最小非负整数解呐?实在是想不出来,各种博客看看,对一元线性同余方程有了进一步的认识。 感谢konjac蒟蒻大佬写的博客~ #include&amp;amp;lt;iostream&amp;amp;gt; #include&amp;amp;lt;cstdio&amp;amp;gt; #include&amp;amp;lt;cstring&amp;am

ó 277
上一篇: HDU 1695 GCD(欧拉函数+容斥原理)
下一篇: SGU 101 Domino(无向图的欧拉路径)
Unin88
博客等级 码龄12年 6粉丝 240原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值