本来不想发这篇博客的
但是考虑到这是人生中第一次atcoder abc做出5道题
还是忍不住发一波
看到了就很慌
作为史上做过的最难得abcT1,居然不是像140那种的直接输出 N 3 N^3 N3
翻译一下题意,输出 小 于 n 的 奇 数 个 数 n \frac{小于n的奇数个数}{n} n小于n的奇数个数
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=1e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
x=0;int f=1;
char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
x*=f;
}
int n;
int main()
{
read(n);
printf("%lf\n",1.*((n+1)/2)/n);
return 0;
}
有n个人,每个人有一个身高
问有几个人身高大于等于k
感觉这道题比上一题简单
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=2e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
x=0;int f=1;
char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
x*=f;
}
int n,k,ans;
int a[N];
int main()
{
read(n),read(k);
Rep(i,1,n)read(a[i]);
Rep(i,1,n)if(a[i]>=k)ans++;
printf("%d\n",ans);
return 0;
}
给一个数组a,按 a i a_i ai从小到大排序输出id
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=2e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
x=0;int f=1;
char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
x*=f;
}
int n;
struct node{
int t,id;
bool operator < (const node &cmp)const{
return t<cmp.t;
}
}a[N];
int main()
{
read(n);
Rep(i,1,n)read(a[i].t),a[i].id=i;
sort(a+1,a+n+1);
Rep(i,1,n)printf("%d ",a[i].id);
puts("");
return 0;
}
这道题…WA了4次
细节处理很多
根据面向数据编程原则
易证:此题答案为输出n的质因数个数
证明:略
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=1e5+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
x=0;int f=1;
char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
x*=f;
}
ll a,b;
ll x;
ll ans=1;
int main()
{
read(a),read(b);
x=__gcd(a,b);
for(ll i=2;i*i<=x;i++){
if(x%i==0)ans++;
while(x%i==0){
x/=i;
if(x==1)break;
}
}
if(x>1)ans++;
printf("%lld\n",ans);
return 0;
}
最为第一次写出来的T5
还是很值得纪念的
事后发现 这道题其实代码非常短
但是对于状压DP一窍不通的我还是硬着头皮写出来了
其实就是个状压的板子题
一看数据 N ≤ 12 N\leq12 N≤12, M ≤ 3000 M\leq3000 M≤3000就知道了
f i , j f_{i,j} fi,j表示前i把钥匙开成j状态的最小花费
其实开一维就可以额,但是由于本人实在是太菜了
所以写出了一个70多行的程序…
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=1005;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
x=0;int f=1;
char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
x*=f;
}
int n,m,high;
int ans=INT_MAX;
int a[N],b[N],c[N][20];
int f[N][5005];
inline int Qpow(int base,int ind){
int res=1;
while(ind){
if(ind&1)res*=base;
base*=base;
ind>>=1;
}
return res;
}
inline int change(int x,int i){
int num[15],cnt=0;
memset(num,0,sizeof(num));
while(x){
num[++cnt]=x%2;
x/=2;
}
Rep(j,1,b[i])num[c[i][j]]=1;
int res=0;
Rep(j,1,n)res+=num[j]*Qpow(2,j-1);
return res;
}
int main()
{
memset(f,0x3f,sizeof(f));
read(n),read(m);
high=Qpow(2,n)-1;
f[0][0]=0;
Rep(i,1,m){
read(a[i]);
read(b[i]);
Rep(j,1,b[i])read(c[i][j]);
Rep(j,0,high){
f[i][j]=min(f[i][j],f[i-1][j]);
int nxt=change(j,i);
f[i][nxt]=min(f[i][nxt],f[i-1][j]+a[i]);
}
}
Rep(i,1,m)ans=min(ans,f[i][high]);
if(ans<1e9)printf("%d\n",ans);
else puts("-1");
return 0;
}