1:Counterfeit Dollar 代码实现
#include<iostream>
#include<string.h>
#include<string>
using namespace std ;
#define int long long
int ans[12] ;
int vis[12] ;
signed main(){
ios::sync_with_stdio(false) ; cin.tie(0) , cout.tie(0) ;
int t1 ;
cin >> t1 ;
while(t1 --){
for(int i = 0 ; i < 12 ; i ++){
ans[i] = - 1;
}
string l[3] , r[3] , j[3] ;
cin >> l[0] >> r[0] >> j[0] >> l[1] >> r[1] >> j[1] >> l[2] >> r[2] >> j[2] ;
for(int i = 0; i < 3 ;i ++){
if(j[i] == "even"){
for(int t = 0 ; t < l[i].size() ; t ++){
ans[l[i][t] -'A'] = 1 ;
}
for(int t = 0 ; t < r[i].size(); t ++){
ans[r[i][t] - 'A'] = 1 ;
}
}else if(j[i] == "up"){
memset(vis , 0 , sizeof(vis)) ;
for(int t = 0 ; t < l[i].size() ; t ++){
int temp = l[i][t] - 'A' ;
if(ans[temp] == -1){
ans[temp] = 2 ;
}
if(ans[temp] == 0){
ans[temp] = 1 ;
}
vis[temp] = 1 ;
}
for(int t = 0 ; t < r[i].size() ; t ++){
int temp = r[i][t] - 'A' ;
if(ans[temp] == -1){
ans[temp] = 0 ;
}
if(ans[temp] == 2){
ans[temp] = 1 ;
}
vis[temp] = 1 ;
}
for(int t = 0 ; t < 12 ; t ++){
if(vis[t] == 0){ // 这里没有出现过的值 全部都是真币
ans[t] = 1 ;
}
}
}else{
memset(vis,0,sizeof(vis)) ;
for(int t = 0 ; t < l[i].size() ; t ++){
int temp = l[i][t] - 'A' ;
if(ans[temp] == -1){
ans[temp] = 0 ;
}
if(ans[temp] == 2){
ans[temp] = 1 ;
}
vis[temp] = 1 ;
}
for(int t = 0 ; t < r[i].size() ; t ++){
int temp = r[i][t] - 'A' ;
if(ans[temp] == -1){
ans[temp] = 2 ;
}
if(ans[temp] == 0){
ans[temp] = 1 ;
}
vis[temp] = 1 ;
}
for(int t = 0 ; t < 12 ; t ++){
if(vis[t] == 0){ // 这里没有出现过的值 全部都是真币
ans[t] = 1 ;
}
}
}
}
for(int i = 0 ; i < 12 ; i ++){
if(ans[i] == 0){
cout << char(i + 'A') << " is the counterfeit coin and it is light." << endl ;
break ;
}else if(ans[i] == 2){
cout << char(i + 'A') << " is the counterfeit coin and it is heavy." << endl ;
break ;
}
}
}
return 0 ;
}
2:Bomb Game 代码实现
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define fast_read ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
const int N = 119 ;
int mp[N][N] , vis[N][N] ;
int ans ;
signed main(){
fast_read ;
int a , b , k ;
cin >> a >> b >> k ;
while(k --){
int r , s , p , t ;
cin >> r >> s >> p >> t ;
int sss = 1 ;
int x_min = max(sss , r - p / 2) , x_max = min(r + p / 2 , a) ;
int y_min = max(sss, s - p / 2) , y_max = min(s + p / 2 , b) ;
if(t == 0){ // 炸弹没有影响到的格子肯定没有碉堡
for(int i = x_min ; i <= x_max ; i ++){
for(int j = y_min ; j <= y_max ;j ++){
mp[i][j] = 1 ;
}
}
}else{
memset(vis , 0 , sizeof(vis)) ;
for(int i = x_min ; i <= x_max ; i ++){
for(int j = y_min ; j <= y_max ;j ++){
vis[i][j] = 1 ;
}
}
for(int i = 1 ; i <= a ; i ++){
for(int j = 1 ; j <= b; j ++){
if(vis[i][j] == 0){
mp[i][j] = 1 ;
}
}
}
}
}
for(int i = 1 ; i <= a ;i ++){
for(int j = 1 ; j <= b ; j ++){
if(mp[i][j] == 0){
++ ans ;
}
}
}
cout << ans ;
return 0 ;
}
3:2011代码实现
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define fast_read ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
int t ;
const int N = 299 ;
int b[N] , len ;
string a ;
int a1 = 2011 , mod = 10000 ;
void div(){
for(int i = b[0] ;i >= 1 ; i --){
if(i > 1) b[i - 1] += b[i] % 2 * 10 ;
b[i] /= 2 ;
}
int i = b[0] ;
while(b[i] == 0) i -- ;
if(i == 0){
b[0] = 1 ;
}else{
b[0] = i ;
}
}
void solve(int a , int mod){
int res = 1 ;
while( !(b[0] == 1 && b[1] == 0)){
if(b[1] % 2 == 1){
res = res * a % mod ;
}
a = a * a % mod;
div() ;
}
cout << res << endl ;
}
signed main(){
fast_read ;
cin >> t ;
while(t --){
cin >> a ;
len = a.size() ;
reverse(a.begin() ,a.end()) ;
for(int i = 0 ; i < len ; i ++){
b[i + 1] = a[i] - '0' ;
}
b[0] = len ;
solve(a1 , mod) ;
}
return 0 ;
}
4:输出前k大的数
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define fast_read ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
const int N = 1e5 + 99 ;
int a[N] , n, temp[N] ;
void merge_sort(int l ,int r){
if(l >= r) return ;
int mid = (l + r) >> 1 ;
merge_sort(l , mid) ;
merge_sort(mid + 1 , r) ;
int i = l , j = mid + 1 , k = 0 ;
while(i <= mid && j <= r){
if(a[i] > a[j]){
temp[k++] = a[i] ;
++ i ;
}else{
temp[k++] = a[j] ;
++ j ;
}
}
while(i <= mid){
temp[k++] = a[i] ;
++ i ;
}
while(j <= r){
temp[k++] = a[j] ;
++ j ;
}
for(int i = l , j = 0 ; i <= r ; i ++){
a[i] = temp[j] ;
++ j ;
}
}
signed main(){
fast_read ;
cin >> n ;
for(int i = 0 ; i < n ; i ++){
cin >> a[i] ;
}
merge_sort(0 , n - 1) ;
int k ;
cin >> k ;
for(int i = 0 ; i < k ; i ++){
cout << a[i] << endl ;
}
return 0 ;
}
5:迷宫
#include<bits/stdc++.h>
using namespace std ;
//#define int long long
#define fast_read ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
#define y1 ytr
int t ;
const int N = 110 ;
char mp[N][N] , vis[N][N];
int x1 , y1 ,x2 ,y2 , n , flag ;
int dx[4] = { 0, 0 , 1 , -1} ;
int dy[4] = { 1, -1 , 0 , 0 } ;
struct node{
int x , y ;
};
queue <node> q ;
void bfs(){
while(q.size()){
q.pop() ;
}
q.push({x1 , y1}) ;
while(q.size()){
auto temp = q.front();
q.pop() ;
for(int i = 0 ; i < 4 ; i ++){
int x = temp.x + dx[i] , y = temp.y + dy[i] ;
if(x >= 0 && x < n && y >= 0 && y < n && vis[x][y] == 0 && mp[x][y] != '#'){
if(x == x2 && y == y2){
flag = 1 ;
return ;
}else{
vis[x][y] = 1 ;
q.push({x,y}) ;
}
}
}
}
}
int main(){
fast_read ;
cin >> t ;
while(t --){
flag = 0 ;
memset(vis , 0 , sizeof(vis)) ;
cin >> n ;
for(int i = 0 ; i < n ; i ++){
for(int j = 0 ; j < n ; j++){
cin >> mp[i][j] ;
}
}
cin >> x1 >> y1 >> x2 >> y2 ;
if(mp[x1][y1] == '#' || mp[x2][y2] == '#'){
cout <<"NO" << endl ;
continue ;
}
bfs() ;
if(flag) cout <<"YES" << endl ;
else cout << "NO" << endl ;
}
return 0 ;
}