【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

显然每个数字只可能是1,3,5,7
然后如果3,5,7这些数字出现两次以上。显然两个3||5||7都能被11整除。
然后1的话最多能出现两次。
那么也就是说最多只可能有5位数字。
把小于等于5位的全都枚举一遍。求出合法的就好。
如果n>=5位就直接输出那个最大的就Ok.

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
int ans[]= {2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};
string s;
int kk = 1;

int main()
{
    int t;
    scanf("%d",&t);

    while(t--)
    {
        string s;
        cin>>s;
        LL n=0;
        rep1(i,0,(int)s.size()-1){
            n=n*10+s[i]-'0';
            if(n>317)break;
        }

        printf("Case #%d: ",kk++);
        if(n>317)puts("317");
        else
        {
             int x=lower_bound(ans,ans+19,n)-ans;
             if(ans[x]>n)x--;
             printf("%d\n",ans[x]);
        }

    }
}

原文地址:https://www.cnblogs.com/AWCXV/p/9625390.html

时间: 2024-07-30 03:07:31

【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number的相关文章

ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number

A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end(

ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship

There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry the weight of V[i]V[i] and the number of the i^{th}ith kind of ship is 2^{C[i]} - 12C[i]?1. How many different schemes there are if you want to use thes

ACM-ICPC 2018 沈阳赛区网络预赛

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解

思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<string> #include<cmath> #include<vector> #include<cstdio> #include<iostream> #include<algori

ACM-ICPC 2018 南京赛区网络预赛 K. The Great Nim Game

题意:有N堆石子(N为大数),每堆的个数按一定方式生成,问先手取若干堆进行尼姆博弈,必胜的方式有多少种. 题解:因为 k < 4096,所以出现的数最多只有4096个,对每个数字只考虑出现奇/偶次进行dp,答案是所有不等于0的dp值的和.然后如果一个数字出现x次,它对自己出现奇数次的方案数和偶数次的方案数贡献都是乘上2 ^ (x - 1),每个数字的贡献都是2 ^ (x - 1) 总贡献就是2 ^ (N - ∑(vis[i])).大数可以一边读入一边取模. 1 #include <bits/s

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心)

分析:贪心地删边后检查每个点的度即可,这也是正确的做法? #include <bits/stdc++.h> using namespace std; const int MAXN = 1e4+5; struct Edge{ int u,v,next; }edges[MAXN<<2]; int head[MAXN],tot; int deg[MAXN]; void init() { memset(head,-1,sizeof(head)); tot =0 ; memset(deg,0

Made In Heaven 2018 沈阳赛区网络预赛 D题

求第k短路 模板题 套模板即可 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> using namespace std; const int maxn=1005; const int maxe=100005; struct State{ int f; // f=g+dis dis表示当前点到终点的最短路径,即之前的