文章目录
题目链接:
https://codeforces.com/gym/287615
https://codeforces.com/gym/287849
A. Omkar and Completion
签到、找规律
/*
* problem:Omkar and Completion
* method:签到
* date:2020/07/15
*/
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1005;
int a[maxn],n,t;
int main(){
cin>>t;
while(t--){
int i;
cin>>n;
for(i=0;i<n;i++){
cout<<1;
if(i!=n-1) cout<<' ';
}
cout<<endl;
}
return 0;
}
B. Omkar and Last Class of Math
找规律、LCM
/*
* problem:Omkar and Last Class of MAth
* method:规律
* date:2020/07/15
*/
#include<iostream>
#define ll long long
using namespace std;
const ll maxn=1005;
int n,t;
int main(){
int i,j;
cin>>t;
while(t--){
cin>>n;
int a,b;
for(i=2;i*i<=n;i++){
if(n%i==0){
int a=n/i;
cout<<a<<' '<<n-a<<endl;
break;
}
}
if(i*i>n) cout<<1<<' '<<n-1<<endl;
}
return 0;
}
C. Omkar and Baseball
找规律:需要的exchange次数为{0,1,2}
/*
* problem:Omkar and Baseball
* method:找规律
* date:2020/07/19
*/
#include<iostream>
#define ll long long
using namespace std;
ll t,n,x[200005];
int main(){
ll i,j,cnt;
cin>>t;
while(t--){
int flag=0;
cin>>n;
cnt=0;
for(i=1;i<=n;i++){
cin>>x[i];
if(x[i]==i) cnt++;
}
if(cnt==n) cout<<"0"<<endl;
else{
for(i=1;x[i]==i;i++) cnt--;
for(i=n;x[i]==i;i--) cnt--;
if(cnt==0) cout<<"1"<<endl;
else cout<<"2"<<endl;
}
}
return 0;
}
A. Magical Sticks
找规律:递增数列规律
/*
* problem:Magical Sticks
* method:找规律(数列和规律)
* date:2020/07/19
*/
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
ll t,n;
int main(){
cin>>t;
while(t--){
cin.tie(0);
cout.tie(0);
cin>>n;
ll t=n/2;
if(2*t!=n) cout<<t+1<<endl;
else cout<<t<<endl;
}
return 0;
}
B. Magical Calendar
找规律:数列
/*
* problem:Magical Calendar
* method:找规律(数列)
* date:2020/07/19
*/
#include<iostream>
#define ll long long
using namespace std;
ll t,x,y;
int main() {
cin>>t;
while(t--) {
cin>>x>>y;
if(x>y) {
cout<<(y+1)*y/2<<endl;
} else {
cout<<(x-1)*x/2+1<<endl;
}
}
return 0;
}
C. A Cookie for You
找规律:大小
/*
* problem: A Cookie for You
* method:找规律(大、小)
* date:2020/07/19
*/
#include<iostream>
#define ll long long
using namespace std;
ll t,a,b,n,m;
int main() {
cin>>t;
while(t--) {
cin>>a>>b>>n>>m;
if(a+b>=m+n) {
if(a<b) {
a^=b;
b^=a;
a^=b;
}
if(b<m) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
} else {
cout<<"No"<<endl;
}
}
return 0;
}
D. Grid-00100
找规律:矩阵
/*
* problem:Grid-00100
* method:找规律
* date:2020/07/19
*/
#include<iostream>
#define ll long long
using namespace std;
int t,n,k;
int x[305][305];
int main(){
int i,j;
cin>>t;
while(t--){
cin>>n>>k;
for(i=0;i<n;i++){
for(j=0;j<n;j++)
x[i][j]=0;
}
if(k%n) cout<<"2"<<endl;
else cout<<"0"<<endl;
i=0;j=0;
while(k--){
if(i==0){
while(x[i][j]) j++;
}
x[i][j]=1;
i=(i+1)%n;
j=(j+1)%n;
}
for(i=0;i<n;i++){
for(j=0;j<n;j++)
cout<<x[i][j];
cout<<endl;
}
}
return 0;
}