1526B. I Hate 1111

B. I Hate 1111:题目

这题目太搞了呀,和dp感觉关系不大,数学题啊
首先要知道,11111能构成后面所有的棍子数。
n = a*111+b*11;

最快做法

//算是规律?
#include <bits/stdc++.h>
using namespace std;
int main()
{int t;cin>>t;while (t--){int n;cin>>n;int k = n/110;int kk = n%11;if (k<kk) cout<<"NO"<<endl;else cout<<"YES"<<endl;}
}

部分暴力

对于互质的m,n。x=a∗m+b∗n。a>=0,b>=0
其中不能构造的最大的数是n ∗ m − n − m
大于n ∗ m − n − m的数,都可以通过m和n构造出来。
所以最大数是1099,以下都可以暴力求。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> a((int)6e5);
vector<int> b((int)3e5), c((int)3e5);
int main()
{int t;cin >> t;while (t--){int n, ff = 0;cin >> n;if (n > 1099)ff = 1;else{for (int i = 0; i * 111 <= n; i++){if ((n - i * 111) % 11 == 0){ff = 1;break;}}}if (ff)cout << "YES" << endl;elsecout << "NO" << endl;}
}

扩展欧几里得求得方程求解

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void gcd(int a,int b,int &d,int &x,int &y)
{if(!b){d=a;x=1;y=0;} else {gcd(b,a%b,d,y,x);y-=x*(a/b);}
}
int main()
{int t;cin>>t;int d,x,y;gcd(11,111,d,x,y);while(t--){int v;cin>>v;LL x0=x*v;LL y0=y*v;LL k=y0/11;if(x0+k*111>=0){cout<<"YES"<<endl;} else {cout<<"NO"<<endl;}}return 0;
}

纯暴力好像也行?

#include<iostream>
using namespace std;
int main()
{int t;cin >> t;while (t--){int x;cin >> x;int flag = 0;for (int i = 0; i < 11; i++){if (x % 11 == 0){flag = 1;break;}x -= 111;if (x < 0)break;}if (flag)cout << "YES" << endl;else cout << "NO" << endl;}
}

纯暴力确实行!

#include <bits/stdc++.h>
using namespace std;
int main()
{int t;scanf("%d",&t);while(t--){int x,flag=0;scanf("%d",&x);for(int i=0;i*111<=x;i++){if((x-i*111)%11==0){cout<<"YES"<<endl;flag=1;break;}}if(!flag)cout<<"NO"<<endl;} return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/428682.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

4. Spring 如何通过 XML 文件配置Bean,以及如何获取Bean

在 Spring 容器内拼凑 bean 叫做装配。装配 bean 的时候&#xff0c;你是在告诉容器&#xff0c;需要哪些 bean &#xff0c;以及容器如何使用依赖注入将它们配合在一起。 理论上&#xff0c;bean 装配的信息可以从任何资源获得&#xff0c;包括属性文件&#xff0c;关系数据库…

1195C. Basketball Exercise

C. Basketball Exercise&#xff1a;题目 经典简单dp&#xff0c;考虑前两天的就行#include <bits/stdc.h> using namespace std; typedef long long ll; vector<int> a((int)6e5); vector<int> b((int)6e5); ll dp[(int)5e5][3]; int main() {int n;cin>…

基于用户击键特征的身份鉴别系统

简单来说&#xff0c;我们要做的就是一种通过用户敲击键盘的习惯进行身份鉴别的系统。国内外之前有一些相关研究&#xff0c;但是通常是数千条数据训练&#xff0c;而且不能随意改变敲击的字符串&#xff0c;或者是有的要求采用带有压力传感器的键盘&#xff0c;难以实用和推广…

1350B. Orac and Models

B. Orac and Models&#xff1a;题目 题意&#xff1a;找一个最长的串&#xff0c;后一个下标可以整除前一个&#xff0c;并且a[i]<a[i1]#include <bits/stdc.h> using namespace std; typedef long long ll; vector<int> a((int)6e5); vector<int> b((i…

linux 配置EPEL源

配置EPEL源[rootansible ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [rootansible ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [rootansible ~]# yum install ansible -y #安装ansible转载于:https://www.cnblogs.c…

B. Mashmokh and ACM

414B. Mashmokh and ACM&#xff1a;题目 1400分就进入经典dp了 题意&#xff1a;给你1-n的数&#xff0c;构造一个长度为k的串&#xff0c;后一个数能整除前一个数#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); …

最长不下降子序列 (O(nlogn)算法)

分析&#xff1a; 定义状态dp[i]表示长度为i的最长不下降子序列最大的那个数。 每次进来一个数直接找到dp数组第一个大于于它的数dp[x]&#xff0c;并把dp[x - 1]修改成 那个数。就可以了 AC代码&#xff1a; # include <iostream> # include <cstdio> # include &…

1380C. Create The Teams

C. Create The Teams&#xff1a;题目 正常人都会用dp吗&#xff1f;不应该是道贪心题吗&#xff1f;#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod …

【DOS】dos命令大全

net use ipipc$ " " /user:" " 建立IPC空链接net use ipipc$ "密码" /user:"用户名" 建立IPC非空链接net use h: ipc$ "密码" /user:"用户名" 直接登陆后映射对方C&#xff1a;到本地为H:net use h: ipc$ 登陆后映…

JS基础_break和continue

1 <!DOCTYPE html>2 <html>3 <head>4 <meta charset"UTF-8">5 <title></title>6 <script type"text/javascript">7 8 /*9 * break关键字可以…

538B. Quasi Binary

B. Quasi Binary&#xff1a;题目 这题目建议挪到1000分&#xff0c;它不配1400#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod 1e9 7; signed main…

289B. Polo the Penguin and Matrix

B. Polo the Penguin and Matrix&#xff1a;题目 思路&#xff1a;纯暴力#include <bits/stdc.h> using namespace std; // #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod 1e9 7; int g[111][11…

HDU 1525 类Bash博弈

给两数a,b&#xff0c;大的数b b - a*k,a*k为不大于b的数,重复过程&#xff0c;直到一个数为0时&#xff0c;此时当前操作人胜。 可以发现如果每次bb%a&#xff0c;那么GCD的步数决定了先手后手谁胜&#xff0c;而每次GCD的一步过程视为一个子游戏&#xff0c;但是可以发现如果…

HDU 3094 树上删边 NIM变形

基本的树上删边游戏 写过很多遍了 /** Date : 2017-10-13 18:19:37* FileName: HDU 3094 树上删边 NIM变形.cpp* Platform: Windows* Author : Lweleth (SoungEarlfgmail.com)* Link : https://github.com/* Version : $Id$*/ #include <bits/stdc.h> #define LL …

1320A. Journey Planning

A. Journey Planning&#xff1a;题目 mp的应用&#xff0c;和下标同样的差一定会越来越大&#xff0c;知道这点就好写了。#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)…

1245C. Constanze‘s Machine

C. Constanze’s Machine&#xff1a;题目 众所周知&#xff0c;斐波那契数列属于dp#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod 1e9 7; map<…

常见三种字符编码的区别:ASCII、Unicode、UTF-8

什么是字符编码&#xff1f; 计算机只能处理数字&#xff0c;如果要处理文本&#xff0c;就必须先把文本转换为数字才能处理。最早的计算机在设计时采用8个比特&#xff08;bit&#xff09;作为一个字节&#xff08;byte&#xff09;&#xff0c;所以&#xff0c;一个字节能表…

1108D. Diverse Garland

D. Diverse Garland&#xff1a;题目 什么脑瘫题目&#xff01;&#xff01;&#xff01;可恶&#xff0c;和dp有什么关系&#xff1f;但是强迫症让我不得不写&#xff0c;空一个很难受&#xff01;&#xff01;#include <bits/stdc.h> using namespace std; #define in…

Oracle存储过程procedure in、out、in out 模式参数【不发布,纯转】

Oracle存储过程procedure in、out、in out 模式参数 Oracle存储过程基本语法介绍 注意存过不会自动提交,需要在存过本身添加commit; rollback;等语句转载于:https://www.cnblogs.com/whatlonelytear/p/7680383.html

1451C. String Equality

C. String Equality&#xff1a;题目 我也不知道这算不算dp....虽然它有一个dp的标签#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod 1e9 7; int mp…