Summer training #4
D:找到两个数 一个是另一个的整数倍(1也算)
因为N是600000 调和级数为ln(n+1) 算一下 可以直接爆
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; bool cmp(int x,int y){return x>y;} int where[600005]; int visit[600005]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n,k; cin >> n >> k; int ans1=0,ans2=0; int t; for(int i=1;i<=k;i++) { scanf("%d",&t); if(visit[t]!=0) //==1 { ans1=where[t]; ans2=i; break; } visit[t]++; where[t]=i; } if(ans1!=0&&ans2!=0) { printf("%d %d\n",ans1,ans2); return 0; } for(int i=1;i<=n;i++) for(int j=2*i;j<=n;j+=i) { if(visit[i]!=0&&visit[j]!=0) { ans1=where[i]; ans2=where[j]; break; } } if(ans1!=0&&ans2!=0) { printf("%d %d\n",ans1,ans2); return 0; } printf("0 0\n"); return 0; }
E:两个板之间的数之和是K的倍数?? 反正这么做过了
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; bool cmp(int x,int y){return x>y;} char a[100005]; //(a1+an)*n/2; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n,k; cin >> n; scanf("%s",a+1); //printf("%s\n",a+1); int num=0; int len=strlen(a+1); //cout <<len<<endl; int first=0,last=0; int pop=1; for(int i=1;i<=len&&pop!=0;i++) { if(a[i]=='1') { //TS; for(int j=i;j<len;j+=n) { //cout << j<<endl; if(a[j+1]=='1') { first=i; last=j+1; pop=0; break; } } } } if(first!=0&&last!=0) { printf("%d %d",first,last); return 0; } printf("0 0\n"); return 0; }
G:水
H:2*3的砖铺 N*M的地板 以前CF好像做过 直接判min(n,m)>=2&&max(n,m)>=3 然后n*m%6==0
证明的话 引用别人的:
乘积是6的倍数那就说明有因子2和3:
1)一边是2的倍数恰好另一边是3的倍数,这种情况下显然可行;
2)一边是6的倍数另一边不是2也不是3的倍数,那另一边肯定是奇数,为1的时候不行,设边为N=2a+1=2(a-1)+3,那前面就以2x3的形式放最后一个以3x2的形式放,由于一边为6的倍数那么就是一定可以放得下的
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int k; cin >> k; while(k--) { ll n,m; cin >> n >> m; ll sum=n*m; if(min(n,m)<2||max(n,m)<3) { cout<<"No"<<endl; continue; } if(sum%6==0) cout <<"Yes"<<endl; else cout <<"No"<<endl; } return 0; }
I:阅读理解 把最长的R B先连起来
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; int red[1005],blue[1005]; bool cmp(int x,int y){return x>y;} int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int n; while(scanf("%d",&n)==1) { mem(red,0); mem(blue,0); int pop=0; int pop1=0; int number=0; int ans=0; char ch; int j; for(int i=1;i<=n;i++) { cin >> j>>ch; if(ch=='R') { red[++pop]=j; } else { blue[++pop1]=j; } } sort(red+1,red+pop+1,cmp); sort(blue+1,blue+pop1+1,cmp); for(int i=1;i<=min(pop,pop1);i++) { ans+=red[i]+blue[i]-2; } cout <<ans<<endl; } return 0; }
J:按条件读取字符 组成词组 输出
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define foror(i,a,b) for(i=a;i<b;i++) #define foror2(i,a,b) for(i=a;i>b;i--) #define EPS 1.0e-8 #define PI acos(-1.0) #define INF 3000000000 #define MOD 1000000009 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define lson o<<1, l, m #define rson o<<1|1, m+1, r //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; //stack<string> a; int pop=0; map<string,int> mp; string strans; int ans=0; char c[550]; //(a1+an)*n/2; void print() { for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++) { if(it->second>ans) { strans=it->first; ans=it->second; } } cout << strans<<":"<<ans<<endl; } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); while(gets(c)) { int len=strlen(c); if(len==4&&c[0]=='#') { print(); mp.clear(); strans=""; ans=0; continue; } else { for(int i=0;i<len;i++) { string start=""; if(c[i]>='a'&&c[i]<='z') { int cur=i; while(c[cur]>='a'&&c[cur]<='z') { start+=c[cur]; cur++; } i=cur; if(c[cur]==','||c[cur]=='\0') continue; start+=' '; while(c[cur]==' ') cur++; while(c[cur]>='a'&&c[cur]<='z') { start+=c[cur]; cur++; } //cout <<"start="<<start<<" "; //cout <<endl; mp[start]++; } } } } return 0; }