标签:names 遍历 ini max 第一个字符 puts line inf 没有
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll T;
cin >> T;
while(T--)
{
ll a, b, n, s;
cin >> a >> b >> n >> s;
if(a*n + b < s) puts("NO");
else
{
if(s - n*a >= 0)
{
s -= n * a;
if(s > b) puts("NO");
else puts("YES");
}
else if(s - n*a < 0)
{
s = s % n;
if(s > b) puts("NO");
else puts("YES");
}
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int a[maxn];
int vis[maxn];
int n;
int main()
{
int T; cin >> T;
while(T--)
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
vis[i] = 0;
}
for(int i = n - 1; i >= 1; i--)
{
if(a[i] > a[i+1])
{
swap(a[i], a[i+1]);
vis[i] = 1;
}
}
for(int i = 1; i <= n - 1; i++)
{
if(vis[i] == 0)
{
if(a[i] > a[i+1])
swap(a[i], a[i+1]);
}
}
for(int i = 1; i <= n; i++)
printf("%d ", a[i]); puts("");
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int c[maxn];
int p[maxn];
int a[maxn];
int n, m, d;
int main()
{
cin >> n >> m >> d;
int sum = 0;
for(int i = 1; i <= m; i++)
{
scanf("%d", &c[i]);
sum += c[i];
}
int cur = 0; //当前的位置
int right = n + 1 - sum;
for(int i = 1; i <= m; i++)
{
p[i] = right;
right += c[i];
}
right = n + 1 - sum;
for(int i = 1; i <= m; i++) //考虑每一块木板
{
if(cur + d < right) //跳不过去
{
p[i] = cur + d; //尽可能的贪心把木板放远一点
cur = cur + d + c[i] - 1;
right += c[i];
}
else //能跳过去
{
cur = n + 1;
break;
}
}
//最后一步还能跳
cur += d;
if(cur <= n) puts("NO");
else
{
puts("YES");
for(int i = 1; i <= m; i++)
for(int j = p[i]; j <= p[i]+c[i]-1; j++)
a[j] = i;
for(int i = 1; i <= n; i++)
printf("%d ", a[i]);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
char s[maxn];
ll n, T, k;
int main()
{
cin >> T;
while(T--)
{
cin >> n >> k;
scanf("%s", s+1);
int cnt = 1;
for(int i = 1; i <= n; i++)
{
if(s[i] == '0' && k >= i - cnt)
{
swap(s[i], s[cnt]);
k -= i - cnt;
cnt++;
}
else if(s[i] == '0' && k < i - cnt && k != 0)
{
for(int j = i - k; j <= i; j++)
if(s[j] == '1') swap(s[j], s[i]);
k = 0;
}
if(k == 0) break;
}
puts(s+1);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
struct Node{
int val;
int idx;
}a[maxn];
bool cmp(Node a, Node b){
return a.val < b.val;
}
int n, f[maxn];
int p[maxn];
int t[maxn];
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &a[i].val);
a[i].idx = i;
}
sort(a, a+n, cmp);
memset(f, 0x3f, sizeof f);
f[0] = 0;
for(int i = 0; i < n; i++)
{
for(int j = 3, delta; j <= 5 && i+j <= n; j++)
{
delta = a[i+j-1].val - a[i].val;
if(f[i+j] > f[i] + delta)
{
p[i+j] = i;
f[i+j] = f[i]+delta;
}
}
}
int cur = n;
int cnt = 1;
while(cur != 0)
{
//因为sort过所以一定是连续的
for(int i = cur - 1; i >= p[cur]; i--)
t[a[i].idx] = cnt;
cnt++;
cur = p[cur];
}
cout << f[n] << " " << cnt - 1 << endl;
for(int i = 0; i < n; i++)
printf("%d ", t[i]); puts("");
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int maxn = 30;
int a[maxn], b[maxn];
int n;
int calc(string s)
{
int cnt = 0;
for(int i = 0; i < n-1; i++)
for(int j = 0; j < n - i; j++)
if(s[j] > s[j+1])
{
cnt++;
swap(s[j], s[j+1]);
}
return cnt % 2;
}
int main()
{
int T;
cin >> T;
while(T--)
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
string s, t;
cin >> n >> s >> t;
for(int i = 0; i < n; i++)
{
a[s[i]-'a']++;
b[t[i]-'a']++;
}
bool flag = 1;
bool jud = 0;
for(int i = 0; i < 26; i++)
{
if(a[i] != b[i]) {
flag = 0;
break;
}
if(a[i] > 1) jud = 1;
}
if(!flag) {
puts("NO");
continue;
}
if(jud) {
puts("YES");
continue;
}
if(calc(s) == calc(t)) puts("YES");
else puts("NO");
}
return 0;
}
标签:names 遍历 ini max 第一个字符 puts line inf 没有
原文地址:https://www.cnblogs.com/zxytxdy/p/11802486.html