A - ABC Swap
水题
AC代码:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b<<endl;
return 0;
}
B - Popular Vote
算总数和每个占总数的百分比
AC代码:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
using namespace std;
int main()
{
int n,m;
int node[110];
cin>>n>>m;
int sum = 0;
int ans = 0;
for(int i=0;i<n;i++)
{
cin>>node[i];
sum+=node[i];
ans = max(ans,node[i]);
}
sort(node,node+n);
int flag = m;
for(int i=n-1;i>=0;i--)
{
if(node[i]>=1.0/(4*m)*sum)
{
flag--;
}
if(flag==0) break;
}
if(flag==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
C - Replacing Integer
题意:给定N和K,只能进行|N-K|的操作,问结果最小是多少(数据较大)
思路:因为有绝对值,N一直减K 直到小于K,这是再减就相当于 K-N,在一直减,在这个过程中找最小值;
第一步,N%K, 此时N小于K,再进行下面计算
|N-K| = K-N
|K-N-K| = N
|N-K| = K-N
一直循环下去
所以只需要比较 N%K 和 K-N%K 哪个比较小。
数据范围较大用 long long
AC代码:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
# define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
double node[maxn];
int main()
{
ll n,k;
cin>>n>>k;
ll a = n%k;
ll b = k-a;
cout<<min(a,b)<<endl;
return 0;
}
D - Lunlun Number
题意:当x 的任意两个相邻数字之间差的绝对值小于等于1 是,x为 lunlun number,请输出第k个 lunlun number;
思路:打表,将范围内的所有 lunlun number 找到,排序,输出第k个即可
打表:如果每个末尾是k,那只能加上k-1,k,k+1,三种情况(按从小到大的顺序记录就不需要再排序),0,9要特判;
AC代码:
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
# define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll node[maxn];
int main()
{
int n;
cin>>n;
int index = 1;
for(index;index<=9;index++)
{
node[index] = index;
}
int i=1;
while(index<=n)
{
if(node[i]%10==0)
{
node[index++] = node[i]*10;
node[index++] = node[i]*10+1;
}
else if(node[i]%10==9)
{
node[index++] = node[i]*10+8;
node[index++] = node[i]*10+9;
}
else
{
node[index++] = node[i]*10+node[i]%10-1;
node[index++] = node[i]*10+node[i]%10;
node[index++] = node[i]*10+node[i]%10+1;
}
i++;
}
cout<<node[n]<<endl;
return 0;
}