A.空间
256 * 1024 * 1024 * 8 / 32 = 67108864
B.卡片
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define mp make_pair
#include<queue>
#include<vector>
#include<iostream>
#include<map>
using namespace std;
#define ll long long
int a[10];
bool w()
{
for(int i=0;i<10;i++)
{
if(a[i]==2021)
{
return 1;
}
}
return 0;
}
void c(int k)
{
while(k)
{
a[k%10]++;
k/=10;
}
}
int main()
{
for(int i=1;;i++)
{
c(i);
if(w()==1)
{
cout<<i<<endl;
return 0;
}
}
return 0;
}
//3181
C.直线
#include <bits/stdc++.h>
#define pb push_back//vector,deque
#define INF 0x3f3f3f3f
#define scd(n) scanf("%d",&n)
#define prd(n) printf("%d",n)
using namespace std;
typedef long long ll;
const int N=1e6+5;
pair<double,double>pi[N];
int cot;
int main() {
int x=20,y=21;
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
for(int k=0;k<x;k++){
for(int m=0;m<y;m++){
int x1=i,y1=j,x2=k,y2=m;
if(x2-x1==0)continue;
double kk=(double)(y2-y1)/(x2-x1);
double b=y2-kk*x2;
pi[cot++]=make_pair(kk,b);
}
}
}
}
int res=1;//假设以k来找k={1,1,2,3,3,5}=1,2,3,5所以一开始res=1
sort(pi,pi+cot);
for(int i=1;i<cot;i++){
if(fabs(pi[i].first-pi[i-1].first)>1e-8||fabs(pi[i].second-pi[i-1].second)>1e-8)
res++;
}
cout<<res+x<<'\n';
return 0;
}
D.货物摆放
#include <bits/stdc++.h>
#define pb push_back//vector,deque
#define INF 0x3f3f3f3f
#define scd(n) scanf("%d",&n)
#define prd(n) printf("%d",n)
using namespace std;
typedef long long ll;
void solve()
{
int t;
cin>>t;
while(t--){
}
}
int cot;
int main() {
ll n=2021041820210418;
vector<ll>v;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
v.push_back(i);
if(n/i!=i)v.push_back(n/i);
}
}
int res=0;
for(auto a:v){
for(auto b:v){
for(auto c:v){
if(a*b*c==n)res++;
}
}
}
cout<<res<<'\n';
// for(auto it:v){
// cout<<it<<'\n';
// }
return 0;
}
E.路径
#include <bits/stdc++.h>
#define pb push_back//vector,deque
#define INF 0x3f3f3f3f
#define scd(n) scanf("%d",&n)
#define prd(n) printf("%d",n)
using namespace std;
typedef long long ll;
const int N=1e5+5;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
struct node{
int u,v,w;
};
vector<node>e;
int dis[2025];
void init()
{
for(int i=1;i<=2021;i++){
for(int j=i+1;j<=2021;j++){
if(abs(i-j)<=21){
e.push_back({
i,j,i*j/gcd(i,j)});
e.push_back({
j,i,i*j/gcd(i,j)});
}
}
}
cout<<e.size()<<'\n';
}
void BF(int n)
{
for(int i=1;i<=n;i++)dis[i]=0x3f3f3f3f;
dis[1]=0;
for(int i=1;i<=n-1;i++){
for(int j=0;j<e.size();j++){
int u=e[j].u,v=e[j].v,w=e[j].w;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
}
}
}
cout<<dis[2021]<<'\n';
}
void solve()
{
int t;
cin>>t;
while(t--){
}
}
int main() {
// solve();//10266837
init();
BF(2021);
return 0;
}
F.时间显示
#include<bits/stdc++.h>
using namespace std;
int main(){
int hh, mm, ss;
long long int n;
cin>>n;
// 因为不需要考虑毫秒,所以直接舍去
n /= 1000;
hh = (n/(60*60)) % 24;
n -= n/(60*60) * (60*60);
mm = (n/60) % 12;
n -= n/60 * 60;
ss = n % 60;
printf("%02d:%02d:%02d", hh, mm, ss);
return 0;
}
G.砝码称重
#include<bits/stdc++.h>
using namespace std;
unordered_set<int> se;
int n, a[100000];
void dfs(int index, int val){
if(index < 0) return;
if(val > 0) se.insert(val);
// 一步一步往下
dfs(index-1, val - a[index-1]);
dfs(index-1, val + a[index-1]);
// 隔级隔级往下
for(int i=2;i<index+1;i++){
dfs(index-i, val + a[index-i]);
}
}
int main(){
cin>>n;
for(int i=0; i<n; i++) cin>>a[i];
sort(a, a+n);
for(int i=0;i<n;i++){
dfs(i, a[i]);
}
// 输出检验
// unordered_set<int>::iterator si;
// for(si=se.begin();si!=se.end();si++){
// cout<<*si<<" ";
// }
// cout<<endl;
cout<<se.size()<<endl;
return 0;
}
H.杨辉三角形
#include <bits/stdc++.h>
using namespace std;
// N是一个个试的,然后发现20000够了,太大超内存,大小找不到最大的数
const int N = 20000;
int a[N][N];
int main(){
int n, s = 0;
cin>>n;
if(n==1){
cout<<1<<endl;
return 0;
}
for(int i=1; i<N;i++){
for(int j=1; j<=i; j++){
s++; // 每数一个数就加一
if(j == 1 || i==j){
a[i][j] = 1;
continue;
}
a[i][j] = a[i-1][j] + a[i-1][j-1];
if(a[i][j] == n){
cout<<s<<endl;
return 0;
}
}
}
return 0;
}
I.双向排序
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[100001],n,m,q,p;
cin>>n>>m;
// 初始化数组
for(int i=1;i<=n;i++) a[i]=i;
while(m--){
cin>>p>>q;
if(p==0) sort(a+1, a+q+1, greater<int>());
else if(p == 1) sort(a+q,a+n+1);
}
for(int i=1; i<=n; i++){
cout<<a[i];
if(i != n) cout<<" ";
}
return 0;
}
J.括号序列
#include<bits/stdc++.h>
using namespace std;
int sum = 0;
void iter(int l, int r, int n){
if(l + r == 2*n) {
sum++;
return;
}
if(l < n) iter(l+1, r, n);
if(r < l) iter(l, r+1, n);
}
int main(){
string s;
getline(cin, s);
int l = 0, r = 0, n;
for(int i=0;i<s.size();i++){
s[i]==')'? r+=1: l+=1;
}
n = max(l, r);
iter(0, 0, n);
cout<<sum<<endl;
return 0;
}
转载:https://blog.csdn.net/zranxi/article/details/116570817
查看评论