//每个unsigned int 有32位,unsigned int target[32]就可表示 32*32个任务ID的状态。 #include<iostream> using namespace std; int main() { unsigned int target[32] = {0}; int ID1, ID2; cin>>ID1>>ID2; if(ID1<1||ID1>1024||ID2<1||ID2>1024) { cout<<-1<<endl; return 0; } int groupID = ID1/32; int indexID = ID1%32; int marktmp = 1<<indexID; target[groupID] = target[groupID]|marktmp; groupID = ID2/32; indexID = ID2%32; marktmp = 1<<indexID; if(marktmp & target[groupID]) cout<<1<<endl; else cout<<0<<endl; return 0; }
#include <iostream> using namespace std; unsigned int buff[32] = {0}; int main(){ int n1, n2; cin >>n1>>n2; unsigned int set = 0x1; set = set << n1%32; buff[n1/32] = buff[n1/32] | set; unsigned int get = 0x1; get = get << n2%32; unsigned int ans = buff[n2/32] & get; cout<<(ans>>n2%32)<<endl; return 0; }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); String id1 = scanner.next(); String id2 = scanner.next(); getAnswer(id1, id2); } public static void getAnswer(String s1, String s2){ HashMap<String, String> index = new HashMap<>(); int id = 1; for(int i=1; i<33; i++){ for(int j=1; j<33; j++){ index.put(String.valueOf(id),String.valueOf(i)+String.valueOf(j)); id++; } } if(!index.containsKey(s1)||!index.containsKey(s2)){ System.out.println(-1); } else if(index.get(s1).equals(index.get(s2))){ System.out.println(1); } else { System.out.println(0); } } }
//使用bitset类 #include<bitset> #include<iostream> bool conditionTest(int num) { if(num>1024 || num<1)return false; else return true; } int main(int argc,char* argv[]) { int first=0,second=0; int ret=0; while(std::cin>>first && std::cin>>second) { std::bitset<1024> task; if(conditionTest(first)&& conditionTest(second)) { task[first-1]=1; if(task.test(second-1)) ret=1; else ret=0; } else ret=1; std::cout<<ret<<std::endl; } }
#include<iostream>
using namespace std;
//设置num的第x位为1,高位在左低位在右,第1位在最低位
void SetBit(unsigned int & num, int x)
{
unsigned int n = 1;
n = n << (x-1);
num = num | n;
}
//获取num的第x位的值,高位在左低位在右,第1位在最低位
int GetBit(unsigned int num, int x)
{
unsigned int n = 1;
n = n << (x - 1);
num = num & n;
if (0 != num)
{
return 1;
}
return 0;
}
int main()
{
unsigned int arr[32] = { 0 };//arr[0],arr[1]...arr[31]
unsigned int p, q;
cin >> p >> q;
if( (p<1)||(p>2014)|| (q < 1) || (q > 2014))
{
cout << 1;
return 0;
}
int i = (p - 1) / 32 + 1;//矩阵的第i个元素,对应arr[i-1]
int x = p % 32;//unsigned int型,最低位第1位,最高位第32位,现在第x位
if (0 == x)
{
x = 32;
}
int j= (q - 1) / 32 + 1;
int y = q % 32;
if (0 == y)
{
y = 32;
}
SetBit(arr[i-1], x);//设置arr[i-1]元素的第x位为1,则表示p个任务已做完
if (1 == GetBit(arr[j-1],y))
{
cout << 1;
}
else
{
cout << 0;
}
//cout << arr[0] << endl;
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int[] a = new int[32];
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int id1 = sc.nextInt();
int id2 = sc.nextInt();
int result = signAndRet(id1,id2,a);
System.out.println(result);
}
}
public static int signAndRet(int id1,int id2,int[] a){
if(id1 < 1 || id1 > 1024 || id2 < 1 || id2 > 1024){
return -1;
}
int groupId = id1/32; //组号码
int index = id1%32; //第几位
int value = 1 << index;
if((value & a[index]) == 0){
a[index] += value;
}
groupId = id2/32;
index = id2%32;
value = 1 << index;
if((value & a[index]) == 0){
return 0;
}
return 1;
}
}
#include<iostream>
using namespace std;
unsigned int fin[32];
int main() {
unsigned int res, a, b;
cin >> a >> b;
if (a < 1 || a > 1024 || b < 1 || b > 1024)res = 1;
else {
a--, b--;
fin[a / 32] |= 1 << (a % 32);
res = (fin[b / 32] & (1 << (b % 32)));
}
cout << (res > 0 ? 1 : 0) << endl;
return 0;
}
#include <iostream> using namespace std; int main() { unsigned int *mission_list=new unsigned int[32]; for(int i=0;i<32;i++) { mission_list[i]=0; } int id1,id2; cin>>id1>>id2; if(id1<1||id1>1024||id2<1||id2>124) { cout<<1<<endl; } else { int list1_index=id1/32; int list1_index_two=id1%32; int list2_index=id2/32; int list2_index_two=id2%32; unsigned int change=1; change=change<<list1_index_two; mission_list[list1_index]+=change; unsigned int test=1; test=test<<list2_index_two; cout<<mission_list[list2_index]<<endl; cout<<test<<endl; if(mission_list[list2_index]&test==1) { cout<<1<<endl; } else { cout<<0<<endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; void Set(uint32_t ntb[], uint32_t setN) { uint32_t row = (setN - 1) / 32; uint32_t column = (setN - 1) % 32; uint32_t setbit = 1 << (column); ntb[row] |= setbit; } void Get(uint32_t ntb[], uint32_t getN) { uint32_t row = (getN - 1) / 32; uint32_t column = (getN - 1) % 32; uint32_t getbit = 1 << column; cout << (getbit & ntb[row] ? 1 : 0) << endl; } int main() { uint32_t ntb[32]; memset(ntb, 0, sizeof(ntb)); uint32_t setN, getN; while(cin >> setN >> getN) { Set(ntb, setN); Get(ntb, getN); } }
//感觉题目的意思是利用unsigned int类型是32位所以用32个32位的unsigned int类型来表示1024个任务 //所以我就设了一个32大小的数组,每个元素都有32位,每一位代表一个任务,通过位操作来完成。 #include<iostream> using namespace std; int main(){ int a,b,c,d; cin>>a>>b; unsigned int m[32]; for(int i=0;i<32;i++) m[i]=0x0000; if(a<1||a>1024||b<1||b>1024){ cout<<1; return 0; } c=a/32; d=a%32; m[c]=m[c]|(1<<(d-1)); c=b/32; d=b%32; if(m[c]>>(d-1)&1){ cout<<1; } else cout<<0; system("pause"); return 0; }
#include<stdio.h> #include<iostream.h> int main() { unsigned int taskDone[1024]; memset(taskDone, sizeof(unsigned int), 1024); unsigned int taskID1, taskID2; cin >> taskID1 >> taskID2; unsigned int ret; if(taskID1>1024) { ret = 1; cout << ret << endl; return 0; } else { taskDone[taskID1 - 1] = 1; if(taskID2 > 1024) { ret = 1; cout << ret << endl; return 0; } else{ if(taskDone[taskID2-1] == 0){ ret = 0; cout << ret << endl; return 0; } else{ ret = 1; cout << ret << endl; return 0; } } } }