【LGR-196-Div.4】洛谷入门赛 #26
相识于 2016
注意到月 , 月.于是答案等于现在月份.
#include<bits/stdc++.h>
using namespace std;
signed main()
{
int y,m;
cin>>y>>m;
cout<<(y-2016)*12+m-7;
return 0;
}游戏与共同语言
你咕请€€£来造的数据,反了第三个判断都能过
直接用pair比较即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main()
{
pair<pair<int,int>,int> a,b;
cin>>a.first.first>>a.first.second>>a.second;
cin>>b.first.first>>b.first.second>>b.second;
a.second = -a.second;
b.second = -b.second;
cout<<(a>b?'A':'B');
return 0;
}皆与生物有缘
注意到,直接求出即可.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main()
{
ll n;
cin>>n;
double a=0,b=0;
for(ll i=1;i<=n*2;++i){
ll x;
cin>>x;
a+=x;
}
cout<<ll(ceil(a/2));
return 0;
}两座城市的 543 千米
只需要循环每一条线,如果扫到就标记,扫到就判断是否打过标记,如果有更新答案,然后跳到下一条线.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100+10,M=1000+10;
ll n,m,a,b,ans;
ll l[M];
ll c[M][M];
signed main()
{
cin>>n>>m>>a>>b;
for(ll i=1;i<=m;++i){
cin>>l[i];
for(ll j=1;j<=l[i];++j){
cin>>c[i][j];
}
}
for(ll i=1;i<=m;++i){
ll flg=0;
for(ll j=1;j<=l[i];++j){
if(c[i][j]==a){
flg=1;
}
if(c[i][j]==b){
if(flg){
++ans;
}
break;
}
}
}
cout<<ans;
return 0;
}于抑郁中支持
令
存储满足的的数量
找出中有几个元素有值
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,M=1000+10;
ll n,t,ans;
ll a[N];
signed main()
{
cin>>n>>t;
ll P=1;
for(ll i=1;i<=t;++i){
P = (P<<3)+(P<<1);// P*=10;
}
for(ll i=1;i<=n;++i){
ll x;
cin>>x;
++a[x%P];
}
for(ll i=0;i<P;++i){
ans+=!(!a[i]);
}
cout<<ans;
return 0;
}蓝色的网易云
用表示题材为的第首歌的编号,每次交替输出即可.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,M=1000+10;
ll n,m;
vector<ll> a[M];
signed main()
{
cin>>n>>m;
for(ll i=1;i<=n;++i){
ll x;
cin>>x;
a[x].push_back(i);
}
ll cnt=n/m;
for(ll i=1;i<=cnt;++i){
for(ll j=1;j<=m;++j){
cout<<a[j].back()<<endl;//取尾部
a[j].pop_back();
}
}
return 0;
}因友情而终结
直接进行查找,如果可以在后面改,那就在后面改(可以一次改两个)
反之在前面改
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,M=1000+10;
ll ans;
string s;
string x="friend";
signed main()
{
ll ind=0;
cin>>s;
while((ind=s.find(x,ind))!=string::npos){//循环找到每一个"friend"
if(ind+8<s.size()){//够改
s[ind+5]='l';
s[ind+6]='o';
s[ind+7]='v';
s[ind+8]='e';
ind+=9;
}
else{
s[ind]='l';
s[ind+1]='o';
s[ind+2]='v';
s[ind+3]='e';
ind+=6;
}
++ans;
}
cout<<ans;
return 0;
}保持连接的方式
如果能插就插,不能就弹最小的.
直接模拟.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k, t;
vector <int> p[105][105];
signed main()
{
cin>>n>>m>>k>>t;
while (t -- ) {
int a, x, y;
cin>>a>>x>>y;
if (p[x][y].size() == k) {
int minn = 1e18, at;
for (int i = p[x][y].size() - 1; i >= 0; -- i ) {
if (p[x][y][i] < minn) {
minn = p[x][y][i];
at = i;
}
}
cout << p[x][y][at] << ' ' << (int)p[x][y].size() - at - 1 << endl;
p[x][y].erase(p[x][y].begin() + at);
p[x][y].push_back(a);
} else {
p[x][y].push_back(a);
puts("-1");
}
}
return 0;
}