ABCDEFGHIJ
A set里一丢,暴力跑就完了
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
int t,n,m;
ll a[maxn],b[maxn];
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
ll ans = 0;
set<ll> male[2],female[2];
for(int i=0;i<n;i++)scanf("%lld",&a[i]);
for(int i=0;i<m;i++)scanf("%lld",&b[i]);
for(int i=0,x;i<n;i++){
scanf("%d",&x);
male[x].insert(a[i]);
}
for(int i=0,x;i<m;i++){
scanf("%d",&x);
female[x].insert(b[i]);
}
/*for(ll i:male[0])printf("%lld ",i);
printf("\n");
for(ll i:male[1])printf("%lld ",i);
printf("\n");
for(ll i:female[0])printf("%lld ",i);
printf("\n");
for(ll i:female[1])printf("%lld ",i);
printf("\n");*/
for(ll i:female[1]){
ll x = *male[0].begin();
while(male[0].size() && x<i){
male[0].erase(x);
x = *male[0].begin();
}
if(!male[0].size())break;
//printf("%lld %lld\n",i,x);
male[0].erase(x);
ans++;
}
for(ll i:male[1]){
ll x = *female[0].begin();
while(female[0].size() && x<i){
female[0].erase(x);
x = *female[0].begin();
}
if(!female[0].size())break;
//printf("%lld %lld\n",i,x);
female[0].erase(x);
ans++;
}
printf("%lld\n",ans);
}
return 0;
}/*
1
3 3
1 2 5
3 4 6
1 1 0
0 0 1
*/
B
化简下,易得是求e/2+e/4+e/8+*****
t = int(input())
while t!=0:
t=t-1
n = int(input())
ans = 0
while n/2!=0:
ans = ans+n/2
n = n/2
print(ans)
C
要是不捡垃圾,容易得出如果已经走过的点就不用再走了,可以直接break
但是要是捡垃圾,那,清空标记重新走即可,虽然不是很优,但是跑的还挺快
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+7;
int t,n,m,x,y;
ll k;
int mmp[maxn][maxn];
bool vis[4007];
char s[250];
int main(){
scanf("%d",&t);
while(t--){
memset(vis,0,sizeof vis);
int ans = 0,cnt = 0;
scanf("%d%d",&n,&m);
scanf("%d%d%lld",&x,&y,&k);
scanf("%s",s);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
scanf("%1d",&mmp[i][j]);
if(mmp[i][j] == 2)cnt++;
}
vis[x*m+y] = 1;
if(cnt != 0)
for(ll i=1;i<=k;i++){
int pos = 3*3*3*3*mmp[x][y]+3*3*3*mmp[x-1][y]+3*3*mmp[x+1][y]+3*mmp[x][y-1]+mmp[x][y+1];
pos %= 243;
if(s[pos] == 'I')break;
if(s[pos] == 'P' && mmp[x][y] == 2){
ans++,mmp[x][y] = 0;
memset(vis,0,sizeof vis);
if(ans == cnt)break;
}
else if(s[pos] == 'U' && x-1>1)
x--;
else if(s[pos] == 'D' && x+1<n)
x++;
else if(s[pos] == 'L' && y-1>1)
y--;
else if(s[pos] == 'R' && y+1<m)
y++;
if(vis[x*m+y])break;
vis[x*m+y] = 1;
}
printf("%d\n",ans);
}
return 0;
}
/*
2
5 5
2 4 6
RUPIRPIUDDLRUDRURLIIURDLPRDLDIRLIDPPRRRLLULPRPUPPDPRIUIUDLULIRIDIRPUPPIRRLRLULUPLRIIRLPRLLRLDLLPDRUUDLDPRRPLLPPUIUUPPLUIILLDRIDILDRRUPLPPLPDLDPDDUPIPPUIILIPLUPLURRPIIDDPPIUPRPRIRDRPPIUIRDUUUPPPDIIRPURIUIUIPLRILLDPPPURPPRRPDPRRLUDUDUDUPRLIUIRLR
11111
12021
10101
12021
11111
4 5
2 2 1000000000000000000
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
11111
10021
11211
11111
*/
E 签到
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
int t,n;
ll a[maxn],b[maxn];
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)scanf("%lld",&b[i]);
ll sum = 0;
int flag = 0;
for(int i=n;i;i--){
if(a[i]<=b[i])
sum += b[i]-a[i];
else{
if(sum>=a[i]-b[i])
sum -= a[i]-b[i];
else{
flag = 1;break;
}
}
}
if(flag)printf("No\n");
else printf("Yes\n");
}
return 0;
}
G 队友写的,不想动
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define pil pair<int,ll>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
const int N = 1e6+5;
ll x, f[N], z[N];
int main()
{
int t;
FAST_IO;
for(cin>>t;t;t--)
{
ll mx = 0;
int n, k;
int cf = 0, cz = 0;
cin>>n>>k;
for(int i=0; i<n; i++)
{
cin>>x;
if(x < 0) f[cf++] = -x;
if(x > 0) z[cz++] = x;
mx = max(mx, abs(x));
}
sort(f, f + cf, greater<int>());
sort(z, z + cz, greater<int>());
int l, r;
ll ans = 0;
for(int i=0;i<cf;i+=k) ans += f[i]*2;
for(int i=0;i<cz;i+=k) ans += z[i]*2;
ans -= mx;
printf("%lld\n", ans);
}
return 0;
}
J
SB 题,暴力就是不给过、、
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn = 1e3+7;
int t;
int main(){
srand(time(0));
scanf("%d",&t);
ll n;
while(t--){
scanf("%lld",&n);
printf("%lld %lld\n",8ll*n,9ll*n);
}
return 0;
}