标签:csrf i++ square freopen targe ati c11 size scanf
水题
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 6 int main() 7 { 8 ll n; 9 cin>>n; 10 for(int i=1;i<=n;i++) 11 { 12 if(i*i<=n&&(i+1)*(i+1)>n){ 13 cout<<i*i<<endl; 14 break; 15 } 16 } 17 return 0; 18 }
H题:Rotation II
水题
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 string s,t,s1,t1; 6 int main() 7 { 8 cin>>s>>t; 9 int len1=s.size(); 10 int len2=t.size(); 11 int flag=0; 12 for(int i=0;i<len1;i++) 13 { 14 if(t[len1-i-1]!=s[i]) 15 { 16 flag=1; 17 break; 18 } 19 } 20 if(flag) 21 cout<<"NO"<<endl; 22 else cout<<"YES"<<endl; 23 24 25 return 0; 26 }
题目的意思是让你在a,b,c三个数组里找三个数使得a[i]<b[i]<c[i],问你能找到多少个这样的序列
我们可以把这三个数组合并在一个数组,定义一个结构体,结构体里用一个变量来标志是哪一个数组里的元素,这里我们用1,2,3分别代表a,b,c里的元素,然后按照数值从小到大排列,如果数值相等就按照标志从大到小排列,最后遍历一遍就可以了。
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 typedef long long ll; 5 struct node 6 { 7 int f,val; 8 }mp[500000]; 9 //int mp[1000005],a[100005],b[100005],c[100005]; 10 bool cmp(node a,node b) 11 { 12 if(a.val==b.val) return a.f>b.f; 13 return a.val<b.val; 14 } 15 int n; 16 int main() 17 { 18 // freopen("in.txt","r",stdin); 19 scanf("%d",&n); 20 int x; 21 for(int i=0;i<n;i++){ 22 scanf("%d",&x); 23 mp[i].val=x; 24 mp[i].f=1; 25 } 26 for(int i=0;i<n;i++){ 27 scanf("%d",&x); 28 mp[i+n].val=x; 29 mp[i+n].f=2; 30 } 31 for(int i=0;i<n;i++){ 32 scanf("%d",&x); 33 mp[i+2*n].val=x; 34 mp[i+2*n].f=3; 35 } 36 sort(mp,mp+3*n,cmp); 37 ll ans=0,p=0,q=0,qq=0; 38 int tmp1,tmp2; 39 for(int i=0;i<3*n;i++) 40 { 41 if(mp[i].f==1) 42 { 43 p++; 44 } 45 else if(mp[i].f==2) 46 { 47 48 q=p; 49 qq+=q; 50 } 51 else 52 { 53 54 ans+=qq; 55 } 56 } 57 printf("%lld\n",ans); 58 return 0; 59 }
标签:csrf i++ square freopen targe ati c11 size scanf
原文地址:https://www.cnblogs.com/scott527407973/p/9417468.html