CodeForces 1417B Two Arrays
題目連線
題意:
給你一個組數和一個不幸數字T,要求把陣列分成兩部分,標記為1or0,同為1或者0的兩個數相加儘可能的不等於T,求任意一種分法。
解題思路:
T/2+T/2=T,既然這樣,把所有小於T/2的數字放在一邊,大於T/2的數放在另一邊,這樣無論怎麼加都不會加到T。剛好等於T/2的資料就一個為0一個為1這樣交替分開放。
#include<bits/stdc++.h>
#define maxn 1000001
using namespace std;
long long int a[maxn];//int會TE
int main()
{
int num;
cin>>num;
while(num--)
{
long long int n,T;
cin>>n>>T;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int x=1;
for(int i=1;i<=n;i++)
{
if(T%2!=0)
{
int t=T/2;
if(a[i]>t)
{
a[i]=1;
}
else
{
a[i]=0;
}
}
else
{
int t=T/2;
if(a[i]>t)
{
a[i]=1;
}
else if(a[i]<t)
{
a[i]=0;
}
else
{
a[i]=x;
x=1-x;
}
}
}
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
return 0;
}
相關文章
- Swift-Median of Two Sorted ArraysSwift
- LeetCode | 349 Intersection Of Two ArraysLeetCode
- Leetcode Median of Two Sorted ArraysLeetCode
- Leetcode 4 Median of Two Sorted ArraysLeetCode
- Leetcode-Median of Two Sorted ArraysLeetCode
- LeetCode 4. Median of Two Sorted ArraysLeetCode
- leetcode 350. Intersection of Two Arrays IILeetCode
- 349. Intersection of Two Arrays--LeetCode RecordLeetCode
- LeetCode2:Median of Two Sorted ArraysLeetCode
- LeetCode Median of Two Sorted Arrays(004)解法總結LeetCode
- 350. Intersection of Two Arrays II--LeetCode RecordLeetCode
- [LeetCode] 1385. Find the Distance Value Between Two ArraysLeetCode
- CF 773 (Div. 1) D. Two Arrays 雙指標 容斥指標
- [LeetCode] Median of Two Sorted Arrays 兩個有序陣列的中位數LeetCode陣列
- Arrays
- delphi open arrays和dynamic arrays區別
- 六,Arrays
- Arrays Basics
- Educational Codeforces Round 98 (Rated for Div. 2) E. Two Editorials 細節題
- 【java】Arrays類Java
- Arrays工具類
- leetcode 4. Median of Two Sorted Arrays 尋找兩個正序陣列的中位數(困難)LeetCode陣列
- Codeforces 893E Counting Arrays:dp + 線性篩 + 分解質因數 + 組合數結論
- coca after two months vs in two months
- Java中Arrays作用Java
- Java Arrays.sort()Java
- java Arrays陣列Java陣列
- 18_Arrays類
- Arrays.copyOf 函式函式
- Java容器工具類ArraysJava
- Swift-陣列(Arrays)Swift陣列
- JAVA基礎--Arrays類Java
- a tale of two cities
- Two extremes in lifeREM
- Two Pirates - 2
- Arrays.asList存在的坑
- 集合框架3-Arrays 類框架
- Arrays.asList()是個坑