AtCoder Beginner Contest 343
A - Wrong Answer
思路
简单的模拟,事实上我们需要注意一下当a和b都为0的情况
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int a,b;
cin>>a>>b;
int ans=a+b;
// cout<<a+b-1<<endl;
if(ans==0){
cout<<ans+1<<endl;
return ;
}
else{
cout<<ans-1<<endl;
}
return ;
}
signed main(){
int t=1;
while(t--) solve();
return 0;
}
B - Adjacency Matrix
思路
简单的模拟,我写的稍微复杂了一点,如果你跟我写的一样,最后应该也是需要去掉重复元素的,但我总感觉貌似可以直接pass掉重复元素
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
const int N=110;
int a[N][N];
bool st[N][N];
void solve(){
int n;
cin>>n;
// std::map<int, int
std::vector<int> g[N];
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
if(a[i][j]){
// st[i][j]=false;i
g[i].push_back(j);
g[j].push_back(i);
}
}
}
for(int i=1;i<=n;i++){
sort(g[i].begin(),g[i].end());
g[i].erase(unique(g[i].begin(),g[i].end()),g[i].end());
}
for(int i=1;i<=n;i++){
for(auto x:g[i]){
cout<<x<<" ";
}
cout<<endl;
}
return ;
}
signed main(){
int t=1;
while(t--) solve();
return 0;
}
C - 343
思路
虽然数据有点大,但是开long long还是可以过的,这里我们只需要枚举i * i * i<=n就可以,最大也就是1e6吧,所以一遍循环是可以解决的
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
#define debug(x) cout<<"# "<<x<<" "
void solve(){
int n;
cin>>n;
int ans=0;
for(int i=1;i*i*i<=n;i++){
int x=i*i*i;
string s=to_string(x);
if(s==std::string(s.rbegin(),s.rend())){
ans=x;
}
}
cout<<ans<<endl;
}
signed main(){
int t=1;
while(t--) solve();
return 0;
}
D - Diversity of Scores
思路
Code
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin()+1,x.end()
#define debug(x) cout<<"# "<<x<<" "<<endl
// const int N=2e5+10;
void solve(){
int n, t1;
std::cin >> n >> t1;
std::map<int, int> mp;
std::vector<int> s(n);
mp[0] = n;
while (t1--) {
int a,b;
cin>>a>>b;
a--;
if (--mp[s[a]] == 0) {
mp.erase(s[a]);
}
s[a] += b;
mp[s[a]]++;
std::cout << mp.size() << "\n";
}
}
signed main() {
int t=1;
while(t--) solve();
return 0;
}
标签:std,AtCoder,cout,Beginner,int,long,mp,343,define
From: https://www.cnblogs.com/du463/p/18049899