#include
#include
#define ll long long int
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N];
ll sum=0,ai=0,ci=0;
int main()
{
ll n;
cin>>n;
for(ll i=0;i<n;i++)
cin>>a[i];
for(ll i=0;i<n;i++)
cin>>b[i];
for(ll i=0;i<n;i++)
cin>>c[i];
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
for(ll i=0;i<n;i++){
ai=0;ci=0;
while(ai<n&&a[ai]<b[i]) ai++;
while(ci<n&&c[ci]<=b[i]) ci++;
// cout<
sum=sum+((ll)ai*(n-ci));
}
cout<<sum<<endl;
return 0;
}
暴力枚举
#include
using namespace std;
//判断素数
int f(int x)
{
for(int i=2;i<x;i++)
{
if(x%i==0)
return 0;
}
return 1;
}
int main()
{
int ans,num,d;
//当ans=10时,从公差=1开始遍历寻找最小公差
for(int i=2;i<50000;i++)//枚举首项
if(f(i))
{
//如果是素数从当前项开始
for(int d=1;d<1000;d++){
for(int j=1;j<1000;j++){
num=i+d*j;
if(f(num)) ans++;
else {
ans=1;break;
}
if(ans==10){
cout<<d;
return 0;
}
}
}
}
return 0;
}
#include
using namespace std;
double dp[35][35] = {{0},{
0,7},{
0,5,8},{
0,7,8,8},{
0,9,2,7,2},{
0,8,1,4,9,1},{
0,8,1,8,8,4,1},{
0,7,9,6,1,4,5,4},{
0,5,6,5,5,6,9,5,6},{
0,5,5,4,7,9,3,5,5,1},{
0,7,5,7,9,7,4,7,3,3,1},{
0,4,6,4,5,5,8,8,3,2,4,3},{
0,1,1,3,3,1,6,6,5,5,4,4,2},{
0,9,9,9,2,1,9,1,9,2,9,5,7,9},{
0,4,3,3,7,7,9,3,6,1,3,8,8,3,7},{
0,3,6,8,1,5,3,9,5,8,3,8,1,8,3,3},{
0,8,3,2,3,3,5,5,8,5,4,2,8,6,7,6,9},{
0,8,1,8,1,8,4,6,2,2,1,7,9,4,2,3,3,4},{
0,2,8,4,2,2,9,9,2,8,3,4,9,6,3,9,4,6,9},{
0,7,9,7,4,9,7,6,6,2,8,9,4,1,8,1,7,2,1,6},{
0,9,2,8,6,4,2,7,9,5,4,1,2,5,1,7,3,9,8,3,3},{
0,5,2,1,6,7,9,3,2,8,9,5,5,6,6,6,2,1,8,7,9,9},{
0,6,7,1,8,8,7,5,3,6,5,4,7,3,4,6,7,8,1,3,2,7,4},{
0,2,2,6,3,5,3,4,9,2,4,5,7,6,6,3,2,7,2,4,8,5,5,4},{
0,7,4,4,5,8,3,3,8,1,8,6,3,2,1,6,2,6,4,6,3,8,2,9,6},{
0,1,2,4,1,3,3,5,3,4,9,6,3,8,6,5,9,1,5,3,2,6,8,8,5,3},{
0,2,2,7,9,3,3,2,8,6,9,8,4,4,9,5,8,2,6,3,4,8,4,9,3,8,8},{
0,7,7,7,9,7,5,2,7,9,2,5,1,9,2,6,5,3,9,3,5,7,3,5,4,2,8,9},{
0,7,7,6,6,8,7,5,5,8,2,4,7,7,4,7,2,6,9,2,1,8,2,9,8,5,7,3,6},{
0,5,9,4,5,5,7,5,5,6,3,5,3,9,5,8,9,5,4,1,2,6,1,4,3,5,3,2,4,1}};
int main(){
for(int i=1;i<=30;i++){
for(int j=1;j<=i;j++){
dp[i][j]=dp[i][j]+dp[i-1][j]/2+dp[i-1][j-1]/2;
}
}
double ans=0x3f3f,max=0;;
for(int i=1;i<=30;i++){
if(dp[30][i]<ans){
ans=dp[30][i];
}
if(dp[30][i]>max){
max=dp[30][i];
}
}
long long p = max * (2086458231 * 1.0 / ans);
cout<<p;
return 0;
}
#include
#include
#include
#include
#include
#include
using namespace std;
const int N=1005;
char a[N][N];
bool v=1,vis[N][N];
int xx[]={1,-1,0,0},yy[]={0,0,1,-1};
bool ok(int x,int y){
return a[x][y]!='.';
}
bool dfs(int x,int y){
vis[x][y]=1;//遍历
if(ok(x-1,y)&&ok(x+1,y)&&ok(x,y+1)&&ok(x,y-1))
v=0;//不沿海
for(int i=0;i<4;i++)//扩张
{
int X=x+xx[i],Y=y+yy[i];
if(ok(X,Y)&&vis[X][Y]==0) dfs(X,Y);
}
a[x][y]='.';
return v;
}
int main()
{
int n,ans=0;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(ok(i,j))//如果是陆地
v=1,ans+=dfs(i,j);
}
cout<<ans<<endl;
return 0;
}
出现次数最多的单词 (https://www.lanqiao.cn/problems/504/learning/)
很长时间再次开始做题,
单词的数量很简单但是开始想到的是映射以及快排。
首先映射的用法不够掌握,不会应用,不知道怎么初始化为0,不知道会用insert()。
快排的话肯定不行,做到一半能意识到,但是以后使用sort的时候请先注意要考虑数组的下标是否可以改变。
#include
using namespace std;
int a[26];
int main()
{
string s;
int max=0;
char x;
cin>>s;
for(int i=0;i<s.length();i++){
a[s[i]-97]++;
}
//sort(a,a+n,cmp);
for(int i=0;i<26;i++){
if(a[i]>max){
max=a[i];
x=i+97;
}
}
cout<<x<<endl<<max<<endl;
return 0;
}
老师答疑顺序安排(https://www.lanqiao.cn/problems/1025/learning/)
没啥意思就是审题
#include
using namespace std;
struct abc{
long int a;
long int b;
long int c;
long int sum;
}x[10000];
bool cmp(abc m,abc n){
return m.sum<n.sum;
}
int main()
{
// 请在此输入您的代码
int num;
cin>>num;
for(int i=0;i<num;i++){
cin>>x[i].a>>x[i].b>>x[i].c;
x[i].sum=x[i].a+x[i].b+x[i].c;
}
sort(x,x+num,cmp);
long long int ans=0;
for(int i=0;i<num;i++){
for(int j=0;j<=i;j++){
if(j==i) ans+=x[j].a+x[j].b;
else ans+=x[j].sum;
// cout<
}
}
cout<<ans<<endl;
return 0;
}