A.Plus or Minus
直接加一下
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005];
signed main(){
int n;
cin>>n;
while(n--){
int a,b,c;
cin>>a>>b>>c;
if(a+b==c){
cout<<"+"<<endl;
}
else{
cout<<"-"<<endl;
}
}
return 0;
}
B.Grab the Candies
把奇数和偶数都加起来,再比大小
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005];
signed main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int odd=0;
int even=0;
int temp=0;
while(n--){
cin>>temp;
if(temp%2==0){
even+=temp;
}
else{
odd+=temp;
}
}
if(even>odd){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return 0;
}
C.Find and Replace
每次将字母转成数字都记录下来,然后判断和前一个是否冲突就行
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[30];
int b[30];
signed main(){
int t;
cin>>t;
while(t--){
for(int i=0;i<30;i++){
a[i]=0;
b[i]=0;
}
int n;
string s;
cin>>n;
cin>>s;
int flag=1;
if(n==1){
cout<<"Yes"<<endl;
continue;
}
else{
a[s[0]-'a']=1;
for(int i=1;i<n;i++){
if(a[s[i]-'a']==0){
if(a[s[i-1]-'a']==1){
a[s[i]-'a']=-1;
}
else{
a[s[i]-'a']=1;
}
}
else{
if(a[s[i]-'a']==a[s[i-1]-'a']){
flag=0;
break;
}
}
}
}
if(flag){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return 0;
}
D.Odd Queries
在输入的时候就把他们都加起来,然后区间修改就方便多了
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int a[200005];
signed main(){
int t;
cin>>t;
while(t--){
int n,q;
cin>>n>>q;
int temp;
for(int i=1;i<=n;i++){
cin>>temp;
a[i]=a[i-1]+temp;
}
while(q--){
int l,r,nums;
cin>>l>>r>>nums;
int num=a[n]-(a[r]-a[l-1])+(r-l+1)*nums;
if(num%2!=0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
}
return 0;
}
E.Interview
思路是二分查找,写的时候出了点小问题,没过,补过的;
遗憾(><)
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005];
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int temp;
int ans;
for(int i=1;i<=n;i++){
cin>>temp;
a[i]=a[i-1]+temp;
}
int l=1;
int r=n;
while(l<=r){
int mid=l+(r-l)/2;
cout<<"?"<<" "<<mid-l+1<<" ";
for(int i=l;i<=mid;i++){
cout<<i<<" ";
}
cout<<endl;
int num;
cin>>num;
if(num>a[mid]-a[l-1]){
ans=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
cout<<"! "<<ans<<endl;
}
return 0;
}
F.Interview
写不来,好困
G1.Subsequence Addition (Easy Version)
排序,然后全加起来,判断这个数与它前面所有数的和的大小关系,若大于,则Yes,反之则No
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int a[5005];
int b[5005];
signed main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
if(n==1){
if(a[0]==1){
cout<<"Yes"<<endl;
continue;
}
else{
cout<<"No"<<endl;
continue;
}
}
int flag=1;
int all=1;
for(int i=1;i<n;i++){
if(all<a[i]){
flag=0;
break;
}
else{
all+=a[i];
}
}
if(flag){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return 0;
}
G2.Subsequence Addition (Hard Version)
和前一个一样只需把数组开大点就行
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
int a[200005];
int b[200005];
signed main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
if(n==1){
if(a[0]==1){
cout<<"Yes"<<endl;
continue;
}
else{
cout<<"No"<<endl;
continue;
}
}
int flag=1;
int all=1;
for(int i=1;i<n;i++){
if(all<a[i]){
flag=0;
break;
}
else{
all+=a[i];
}
}
if(flag){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return 0;
}