黑龙江大学程序设计竞赛(重现赛)
A:
Find the Nth Character
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。题目描述
的同学们上程序算法课的时候出了一道找规律的题目,题目表述如下 假设:


输入描述:
输出描述:
示例1输入
复制6 1 2 3 4 5 10
输出
复制a a b a b d
思路:这个题目似曾相识的感觉。。直接上代码吧
#include<iostream> #include<vector> #include<string> #include<cstring> #include<cmath> #include <algorithm> #include <stdlib.h> #include <cstdio> #include<sstream> #include<cctype> #include <queue> #include <map> #define ll long long using namespace std; char c[10010]; int main() { ll t,q; cin>>t; for(ll i=1;i<=t;i++) { cin>>q;ll k=0; while(q-k*(k+1)/2>0) { k++; } --k; if(q-k*(k+1)/2==0) {if(k%26==0) k=26;else k%=26;cout<<char(96+k)<<endl;} else { q-=k*(k+1)/2; {if(q%26==0) q=26;else q%=26;cout<<char(96+q)<<endl;} } } }
下面代码是借鉴别人的:
#include<iostream> #include<algorithm> #include<cmath> using namespace std; int main() { int n,T; while(~scanf("%d",&T)) { while(T--) { scanf("%d",&n); int x=floor(0.5*(-1+sqrt(1+8*n))-0.001); // printf("x=%d\n",x); x=n-x*(x+1)/2; putchar('a'+(x-1)%26); puts(""); } } return 0; }
C:
爱的魔力转圈圈,想你想到心花怒放黑夜白天,可是我害怕爱情只是一瞬间,转眼会不见,我要慢慢冒险。经过了无数的思想斗争,他要做出这个决定,和喜欢的女孩子表白,但女孩只是留给他一个排列,排列的定义是一个由



输入描述:
第一行是一个数字
输出描述:
一行一个整数表示答案示例1
输入
复制2 3 5
输出
复制3 5
简单暴力。

#include<iostream> #include<vector> #include<string> #include<cstring> #include<cmath> #include <algorithm> #include <stdlib.h> #include <cstdio> #include<sstream> #include<cctype> #include <queue> #include <map> #define ll long long using namespace std; int c[10010]; bool gcd(int a,int b) { if(a<b) swap(a,b); int r=a%b; while(r) { a=b; b=r; r=a%b; } if(b==1) return 1; else return 0; } int main() { for(int i=1;i<=1000;++i) c[i]=i; ll t,q; cin>>t; while(t--) { cin>>q;int Max=-1000; sort(c+1,c+1001); do { int sum=0; if(gcd(c[1],c[q])) ++sum; for(ll i=1;i<q;++i) { if(gcd(c[i],c[i+1])) ++sum; } Max=max(sum,Max); if(sum==q) {break;} }while(next_permutation(c+1,c+t+1)); cout<<Max<<endl; } }View Code
K:
链接:https://ac.nowcoder.com/acm/contest/877/K
来源:牛客网
题目描述

输入描述:

输出描述:

输入
复制2 35 1000000000
输出
复制17 82
说明
In the first example, you can choose, for example,a = 17 andb = 18, so thatS(17) + S(18) = 1 + 7 + 1 + 8 = 17. It can be shown that it is impossible to get a larger answer.
In the second test example, you can choose, for example,a = 500000001 andb = 499999999, withS(500000001) + S(499999999) = 82. It can be shown that it is impossible to get a larger answer.
靠感觉贪心吧。是其中某个数尽可能每一位都是9,比如35,可以是9+(35-9)=35,如果是99就大于35了。

#include<iostream> #include<vector> #include<string> #include<cstring> #include<cmath> #include <algorithm> #include <stdlib.h> #include <cstdio> #include<sstream> #include<cctype> #include <queue> #include <map> #define ll long long using namespace std; int ans[100100],sum[100100]; int main() { ll t,n,m; cin>>t; while(t--) { cin>>n; ll s=0; while(n>s) { s=s*10+9; } s=(s-9)/10; ll sum=0; ll a=n-s; while(s) { sum+=s%10; s/=10; } while(a) { sum+=a%10; a/=10; } cout<<sum<<endl; } }View Code
剩下的有题解后再补

更多精彩